firebase_core plugin is responsible for connecting your Flutter app to your Firebase project. The plugin must be
installed and initialized before the usage of any other FlutterFire plugins. It provides basic functionality such
- Null safety
Ensure you're using the Flutter
If your app is mixing legacy and null-safe packages, use the
For legacy package imports, place the following ignore comment to hide Dart analyzer warnings:
FlutterFire requires a default Firebase app to be present before initialization, otherwise an exception will be thrown. The steps for setting up a default app for your platform can be found in the Getting Started documentation.
Some plugins such as Analytics & Performance Monitoring are only compatible with the default Firebase app, however, plugins such as Authentication can take advantage of Secondary Firebase Apps, allowing you to use multiple Firebase projects at once.
To access the default app, call the
app method on the
Some FlutterFire plugins allow the usage of secondary Firebase apps, letting you interchange the project the plugin uses. Currently, the Firebase SDKs provide functionality for using secondary apps with the following services:
- Realtime Database.
- Cloud Firestore.
- Cloud Functions.
- Cloud Storage.
- Instance ID.
- ML Kit Natural Language.
- ML Kit Vision.
- Remote Config.
To initialize a secondary app, call the
initializeApp method with a name and options:
At a minimum, you must provide the
projectId. Although the other options
are not required, it is recommended you view the
FirebaseOptions reference API for the full list of options available.
Attempting to access an app that does not exist will throw an exception.
Each FlutterFire plugin provides a streamlined approach for using the default app as well as secondary apps (if applicable).
The convenient way to use the default app is by accessing the
instance property on each plugin base class. For example
if using Cloud Firestore:
If instead you'd like to use a secondary app, pass it to the
instanceFor static method on each plugin base class. For
example if using Cloud Firestore:
If you no longer need a secondary app, you can delete it by calling the
delete method on the
Any plugin usage attempting to use a deleted app will throw an exception. The default app cannot be deleted and will throw an exception if deleted.