LoginSignup
0
0

macosのFlutterプロジェクトでFirebase初期化時の問題と解決策

Last updated at Posted at 2024-02-13

macOS向けのFlutterアプリでflutterfire configureコマンドを実行した後、[cloud_firestore/unavailable] The service is currently unavailable.というエラーに遭遇しました。

問題の原因

flutterfire configureコマンドによって、macOS向けのアプリにはGoogleService-Info.plistファイルとfirebase_options.dartが生成されます。
この自動生成されたGoogleService-Info.plistが予期せぬエラーの原因となることがあります。

解決策

この問題を解決するには、以下の手順を実行します。

  1. GoogleService-Info.plistの削除

    macos/RunnerディレクトリからGoogleService-Info.plistファイルを削除します。

  2. firebase_options.dartを使用したFirebaseの初期化

    Firebaseを初期化する際には、firebase_options.dartからDefaultFirebaseOptions.currentPlatformを引数に渡して初期化します。これにより、各プラットフォーム向けの正しいFirebase設定が使用されます。

    import 'package:firebase_core/firebase_core.dart';
    import 'firebase_options.dart';
    
    void main() async {
      WidgetsFlutterBinding.ensureInitialized();
      await Firebase.initializeApp(
        options: DefaultFirebaseOptions.currentPlatform,
      );
      runApp(MyApp());
    }
    
0
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
0
0