LoginSignup
2
0

More than 1 year has passed since last update.

既存のflutterアプリにfirebaseを導入する

Posted at

はじめに

  • 何も設定しなければ、cloud firestoreに繋げれない。当たり前のことだが。
  • 2つしないといけないことがありました。
    1. cloud_firestore: v4.4以外にも、firebase_core: v2.7のpackageのインストールが必要だったこと
    2. apiKeyやappIdなどの幾つかの認証設定
  • firebase cliを使えば簡単に出来ちゃうのだとか

lib/main.dart

void main() async {
  // runApp()より前にFirebaseの設定をしているのならば、以下の記述をしなければならない
  WidgetsFlutterBinding.ensureInitialized();
  // Undefined name 'Firebase'.
  // Try correcting the name to one that is defined, or defining the name.
  await Firebase.initializeApp();
  runApp(const FitnessApp());
}

Firebase CLIから行う手順

  • 自動インストール スクリプトで Firebase CLI をインストールする
curl -sL https://firebase.tools | bash
  • Google アカウントで Firebase にログインして認証
firebase login
  • pathを通して、flutterfire configureコマンドを使用できるように設定する
dart pub global activate flutterfire_cli
export PATH="$PATH":"$HOME/.pub-cache/bin" >> ~/.zshrc
source ~/.zshrc
  • 以下のコマンドから、既存のflutterアプリにでもfirebaseに繋ぐファイルを生成してくれる
flutterfire configure

参考文献

2
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
0