관리 메뉴

cococo-coding

[Flutter] 프로젝트 기본 세팅하기 본문

[Flutter] 두번째 앱/TIL

[Flutter] 프로젝트 기본 세팅하기

_dani 2024. 3. 11. 17:01

감정일기 앱을 만들기 위해 파이어베이스와 플러터를 연결했다. 

 

1. analysis_options.yaml 파일에 다음코드를 추가한다. (Lint가 뜨지 않도록 방지)

  rules:
    prefer_const_constructors: false
    avoid_print: false
    prefer_typing_uninitialized_variables: false
    prefer_const_constructors_in_immutables: false

 

2. main.dart 파일을 다음 코드로 기본세팅한다.

import 'package:flutter/material.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

void main() async{
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp(
    options: DefaultFirebaseOptions.currentPlatform,
  );
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Text('hello'),
    );
  }
}

 

결과

 

위 코드를 크롬으로 열어본 화면이다. 

왼쪽처럼 hello글자가 잘 나타남을 확인할 수 있다.

 

TIL

 

파이어베이스 연결과 기본적인 main 파일 세팅이 적혀있는 글이 없어서 헤맸는데,

파이어베이스 설치를 하고 생성된 파이어베이스 코드를 남겨둔 상태에서 ->  class MyApp~ @override~만 남기고 기본 코드를 지우면 된다.

 

기본적인 main파일세팅은 코딩애플 사이트를 참고했다. 

https://codingapple.com/unit/flutter-basic-layout-widget/?id=19933

 

플러터 기본 위젯 넣는 법 - 코딩애플 온라인 강좌

0:00 첫 프로젝트 셋팅 3:47 디자인은 위젯으로 합니다 그리고 글자와 아이콘  6:57 이미지넣는법 9:28 네모넣는법 저번 시간에 Flutter 프로젝트 새로 생성했죠? 그 상태에서 미리보기 띄우고 시작할

codingapple.com