Core
Notice
This page is archived and might not reflect the latest version of the FlutterFire plugins. You can find the latest information on firebase.google.com:
The 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
as:
#
InstallationThe firebase_core
plugin can be installed by following the Getting Started documentation. Once installed,
import the plugin:
#
Default Firebase appFlutterFire 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 initializeApp
or app
method on the Firebase
class:
#
Secondary Firebase appsSome 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:
- Authentication.
- Realtime Database.
- Cloud Firestore.
- Cloud Functions.
- Cloud Storage.
- Instance ID.
- ML Kit Natural Language.
- ML Kit Vision.
- Remote Config.
#
Initializing secondary appsTo initialize a secondary app, call the initializeApp
method with a name and options:
At a minimum, you must provide the appId
, apiKey
, messagingSenderId
and projectId
. Although the other options
are not required, it is recommended you view the FirebaseOptions
reference API for the full list of options available.
#
Accessing secondary appsOnce initialized, secondary apps can be accessed via the app
method on FirebaseCore
:
Attempting to access an app that does not exist will throw an exception.
It is also possible to get all existing apps at once via the apps
static property on Firebase
class:
#
Using app instancesEach 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:
#
Deleting instancesIf you no longer need a secondary app, you can delete it by calling the delete
method on the FirebaseApp
instance:
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.