본문 바로가기
Flutter

[flutter] 블로그 만들기01 - 프로젝트 기본설정

by JINJINC 2025. 1. 31.
728x90
반응형

의존성

cupertino_icons: ^1.0.8
flutter_svg: ^2.0.6
intl: ^0.18.1
dio: ^5.2.0 # 서버와 통신하기 위해 필요한 라이브러리 입니다.
flutter_riverpod: ^2.3.6 # 상태관리 Riverpod 라이브러리 입니다.
logger: ^1.3.0 # 콘솔창에서 결과물을 쉽게 확인할 수 있도록 하는 Log 라이브러리입니다.
flutter_secure_storage: ^8.0.0 # 어플리케이션 Secure Storage를 쉽게 사용할 수 있도록 도와주는 라이브러리입니다.
pull_to_refresh: ^2.0.0

linter


#linter란?  
# 코드 스타일과 품질을 검사하여 코드에 있는 잠재적 오류  
# 스타일 위반, 비효율적 패턴 등을 알려주는 도구입니다.  
linter:  
  # The lint rules applied to this project can be customized in the  
  # section below to disable rules from the \`package:flutter\_lints/flutter.yaml\`  
  # included above or to enable additional rules. A list of all available lints  
  # and their documentation is published at [https://dart.dev/lints.](https://dart.dev/lints.)  
  #  
  # Instead of disabling a lint rule for the entire project in the  
  # section below, it can also be suppressed for a single line of code  
  # or a specific dart file by using the \`// ignore: name\_of\_lint\` and  
  # \`// ignore\_for\_file: name\_of\_lint\` syntax on the line or in the file  
  # producing the lint.  
  rules:  
    # 상수로 선언 가능한 생성자에 대해 경고를 표시하지 않음으로 설정.  
    prefer\_const\_constructors: false  
    # 변하지 않는 변수에 대해 const로 선언하지 않아도 경고를 표시하지 않음.  
    prefer\_const\_declarations: false  
    # 불변 컬렉션(List, Map, Set 등)에 대해 const를 사용하지 않아도 경고를 표시하지 않음.  
    prefer\_const\_literals\_to\_create\_immutables: false  
    # avoid\_print: false  # Uncomment to disable the \`avoid\_print\` rule  
    # prefer\_single\_quotes: true  # Uncomment to enable the \`prefer\_single\_quotes\` rule  
    # avoid\_print: false  # Uncomment to disable the \`avoid\_print\` rule  
    # prefer\_single\_quotes: true  # Uncomment to enable the \`prefer\_single\_quotes\` rule

기본 페이지 뼈대 작성

import 'package:flutter/material.dart';  

class JoinPage extends StatelessWidget {  
  const JoinPage({super.key});  

  @override  
  Widget build(BuildContext context) {  
    return const Placeholder();  
  }  
}

import 'package:flutter/material.dart';  

class LoginPage extends StatelessWidget {  
  const LoginPage({super.key});  

  @override  
  Widget build(BuildContext context) {  
    return const Placeholder();  
  }  
}

import 'package:flutter/material.dart';  

class PostListPage extends StatelessWidget {  
  const PostListPage({super.key});  

  @override  
  Widget build(BuildContext context) {  
    return const Placeholder();  
  }  
}

import 'package:flutter/material.dart';  

class PostWritePage extends StatelessWidget {  
  const PostWritePage({super.key});  

  @override  
  Widget build(BuildContext context) {  
    return const Placeholder();  
  }  
}

import 'package:flutter/material.dart';  

const double smallGap = 5.0;  
const double mediumGap = 10.0;  
const double largeGap = 20.0;  
const double xlargeGap = 100.0;  

// 간혹 현재 모바일 크기의 가로 , 세로 크기를 동적으로 가져와야 할 때가 있다.  
double getScreenWidth(BuildContext context) {  
  return MediaQuery.of(context).size.width;  
}  

// 응용  
double getDrawerWidth(BuildContext context) {  
  return getScreenWidth(context) \* 0.6;  
}  

double getScreenHeight(BuildContext context) {  
  return MediaQuery.of(context).size.height;  
}

import 'package:flutter/material.dart';  

ThemeData theme() {  
  return ThemeData(  
    appBarTheme: appBarTheme(),  
    useMaterial3: true,  
  );  
}  

AppBarTheme appBarTheme() {  
  return AppBarTheme(  
    titleTextStyle: TextStyle(color: Colors.white, fontSize: 20),  
    centerTitle: true,  
    backgroundColor: Colors.black12,  
    elevation: 0,  
  );  
}

main페이지( 계속 작업중)


import 'package:class\_f\_story/ui/pages/auth/join\_page/join\_page.dart';  
import 'package:class\_f\_story/ui/pages/auth/login\_page/login\_page.dart';  
import 'package:class\_f\_story/ui/pages/post/list\_page/post\_list\_page.dart';  
import 'package:class\_f\_story/ui/pages/post/write\_page/post\_write\_page.dart';  
import 'package:flutter/material.dart';  
import 'package:flutter\_riverpod/flutter\_riverpod.dart';  

void main() {  
  runApp(const ProviderScope(child: MyApp()));  
}  

// 사전 기반 --> Navigator(화면 전환을 관리하는 객체)  -- stack 구조로 화면을 관리 한다.  
GlobalKey<NavigatorState> navigatorkey = GlobalKey<NavigatorState>();  
// 고유 키를 생성 (GlobalKey) -> 모든 위젯은 고유 값을 식별하기 위해 키를 가질 수 있다.  
// 전역 변수로 navigatorkey 선언 -> Navigator 관리 상태에 접근이 가능하다  
// 현재 가장 위에 있는 context 를 알아 낼 수 있습니다.  

class MyApp extends StatelessWidget {  
  const MyApp({super.key});  

  @override  
  Widget build(BuildContext context) {  
    return MaterialApp(  
      // context 가 없는 곳에서 context를 사용할 수 있게 하는 방법  
      navigatorKey: navigatorkey,  
      debugShowCheckedModeBanner: false,  
      home: LoginPage(),  
      // initialRoute: LoginPage(),  
      routes: {  
        "/login": (context) => LoginPage(),  
        "/join": (context) => JoinPage(),  
        "/post/list": (context) => PostListPage(),  
        "/post/write": (context) => PostWritePage()  
      },  
    );  
  }  
}
728x90
반응형

댓글