Flutter에 Firebase 연결하기

송민경's avatar
Aug 28, 2024
Flutter에 Firebase  연결하기

1. Firebase 콘솔로 이동하기

 

2. 프로젝트 만들기

  • 파이어베이스 시작하기 들어가서 프로젝트 생성하기
  • 프로젝트 이름 작성하기
notion image
notion image
notion image
notion image
notion image
 

3. Flutter앱에 Firebase 추가 시작

notion image
 

4. Firebase CLI 설치 및 로그인(firebase login 실행)

notion image
  • 자신의 OS용 Firebase CLI 바이너리를 다운로드
npm install -g firebase-tools
  • Firebase CLI 실행
notion image
  • 로그인하여 CLI 테스트
firebase login
  • YES OR NO를 물어볼때 yes 입력
notion image
  • 브라우저에서 google 로그인을 진행하면 아래 화면이 나옴
notion image
  • CLI도 로그인 테스트가 완료됨
notion image
 

5. Flutter SDK 설치 및 프로젝트 만들기

  • 이미 설치가 되어있기 때문에 넘어감
notion image
 

6. Flutter에서 명령어 입력하기

  • Dart의 패키지 관리 도구 pub을 사용하여 flutterfire_cli 패키지를 전역(global)으로 활성화
dart pub global activate flutterfire_cli
notion image
  • 환경 변수에 경로 추가하기
where firebase // 위치 확인하기
C:\Users\MK\AppData\Local\Pub\Cache\bin
notion image
notion image
notion image
notion image
  • Flutter와 Firebase 연결하기
flutterfire configure --project=fcm-test-aㅇㅇㅇㅇ
  • 윈도우에서 저 명령어로 하다가 오류가 터짐
    • 경로를 지정하여 명령어 실행
    • & "C:\Users\MK\AppData\Local\Pub\Cache\bin\flutterfire.bat" configure --project=fcm-test-abfa1
notion image
 
 
 
notion image
 
  • 스페이스키로 선택, 미선택 가능
  • 패키지명 입력
 
 
 

7. Firebase 초기화 및 플러그인 추가

notion image
  • 라이브러리 추가
firebase_core: ^3.4.0
  • Firebase 초기화는 앱의 실행과 동시에 이루어져야 함 / 비동기식
void main() async { WidgetsFlutterBinding.ensureInitialized(); // Flutter의 위젯 시스템을 초기화 await Firebase.initializeApp( // Firebase를 초기화하는 비동기 함수 options: DefaultFirebaseOptions.currentPlatform, // Firebase 설정을 현재 플랫폼에 맞게 적용 ); runApp(const MyApp()); }
Share article
RSSPowered by inblog