Saturday, 18 June 2022

How do I use FlutterFire with a emulator demo project?

I am using the firebase emulator with demo project, without any actual firebase project resource created. I am doing so with the following command...

firebase emulators:start --project demo-test --only firestore

This successfully starts a Firebase emulator instanceat localhost:8080.

Then I am connecting to the firebase in my flutter app as follows...

await Firebase.initializeApp();
FirebaseFirestore.instance.settings = const Settings(
  host: 'localhost:8080',
  sslEnabled: false,
  persistenceEnabled: false,
);

When initializeApp is run, I get the following error...

E/flutter ( 7724): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: [core/not-initialized] Firebase has not been correctly initialized.
E/flutter ( 7724):
E/flutter ( 7724): Usually this means you've attempted to use a Firebase service before calling `Firebase.initializeApp`.
E/flutter ( 7724):
E/flutter ( 7724): View the documentation for more information: https://firebase.flutter.dev/docs/overview#initialization
E/flutter ( 7724):
E/flutter ( 7724): #0      MethodChannelFirebase.initializeApp
package:firebase_core_platform_interface/…/method_channel/method_channel_firebase.dart:113
E/flutter ( 7724): <asynchronous suspension>
E/flutter ( 7724): #1      Firebase.initializeApp
package:firebase_core/src/firebase.dart:40
E/flutter ( 7724): <asynchronous suspension>
E/flutter ( 7724): #2      _MyHomePageState._asyncInit
package:mobile_app/main.dart:53
E/flutter ( 7724): <asynchronous suspension>
E/flutter ( 7724):


from How do I use FlutterFire with a emulator demo project?

No comments:

Post a Comment