본문 바로가기

Front-End/Flutter

[Flutter] Flutter 앱에 Firebase 추가

Flutter 앱에 Firebase 추가하는 가이드 입니다.

https://firebase.google.com/docs/flutter/setup?hl=ko&platform=android

 

Flutter 앱에 Firebase 추가

Google은 흑인 공동체를 위한 인종적 평등을 추구하기 위해 노력하고 있습니다. 자세히 알아보기 의견 보내기 Flutter 앱에 Firebase 추가plat_iosplat_android 이 가이드에 따라 Flutter 앱에 Firebase 제품을 추

firebase.google.com

 

1단계: Firebase 프로젝트 만들기

https://console.firebase.google.com/u/0/?hl=ko 

 

로그인 - Google 계정

하나의 계정으로 모든 Google 서비스를 Google 계정으로 로그인

accounts.google.com

2단계: Firebase에 앱 등록

 - Android 패키지 이름, 앱 닉네임, SHA1 hash 등록

 

디버그 서명 인증서 SHA-1 생성 방법 

keytool -list -v -alias androiddebugkey -keystore %USERPROFILE%\.android\debug.keystore

3단계: Firebase 구성 파일 추가

google-services.json 파일 추가 (android/app/google-services.json)

android/build.gradle

dependencies {
        classpath 'com.android.tools.build:gradle:4.1.0'
        classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
        classpath 'com.google.gms:google-services:4.3.10'
}

android/app/build.gradle

dependencies {
    implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
    implementation platform('com.google.firebase:firebase-bom:28.4.0')
    implementation 'com.google.firebase:firebase-analytics'
}

apply plugin: 'com.google.gms.google-services'

4단계: FlutterFire 플러그인 추가

flutter pub add firebase_core

 

5단계: Initializing FlutterFire

import 'package:flutter/material.dart';

// Import the firebase_core plugin
import 'package:firebase_core/firebase_core.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(App());
}

/// We are using a StatefulWidget such that we only create the [Future] once,
/// no matter how many times our widget rebuild.
/// If we used a [StatelessWidget], in the event where [App] is rebuilt, that
/// would re-initialize FlutterFire and make our application re-enter loading state,
/// which is undesired.
class App extends StatefulWidget {
  // Create the initialization Future outside of `build`:
  @override
  _AppState createState() => _AppState();
}

class _AppState extends State<App> {
  /// The future is part of the state of our widget. We should not call `initializeApp`
  /// directly inside [build].
  final Future<FirebaseApp> _initialization = Firebase.initializeApp();

  @override
  Widget build(BuildContext context) {
    return FutureBuilder(
      // Initialize FlutterFire:
      future: _initialization,
      builder: (context, snapshot) {
        // Check for errors
        if (snapshot.hasError) {
          return SomethingWentWrong();
        }

        // Once complete, show your application
        if (snapshot.connectionState == ConnectionState.done) {
          return MyAwesomeApp();
        }

        // Otherwise, show something whilst waiting for initialization to complete
        return Loading();
      },
    );
  }
}

 

참고 문서

Firebase Tutorial

https://firebase.google.com/codelabs/firebase-get-to-know-flutter?hl=ko#0 

 

Get to know Firebase for Flutter

Build a Flutter mobile app from scratch with Firebase. You’ll use the FlutterFire packages to talk to Firebase Auth and Cloud Firestore. This is a great introduction to using the Firebase console and integrating Firebase into a Flutter app.

firebase.google.com

'Front-End > Flutter' 카테고리의 다른 글

[Flutter] No version of NDK  (0) 2021.09.18
[Flutter] lints 설정  (0) 2021.08.29
[Flutter] Null Safety migration  (0) 2021.03.29
[Flutter] 다국어 처리 easy_localization  (0) 2021.03.20