use static method
void
use({
- TokenProviderFactory? tokenProviderFor,
- AppCheckProviderFactory? appCheckProviderFor,
- DatabasePersistenceFactory? persistenceFor,
- bool? useDartCore,
Makes firebase_database_dart the implementation of firebase_database
on any platform. Call it at the start of main, before Firebase or
FirebaseDatabase is used. Calling it again replaces the whole
configuration: tokenProviderFor, appCheckProviderFor and
persistenceFor left out of the later call are unset, not kept from the
earlier one. A Dart core an earlier call installed stays installed.
tokenProviderForreturns the token provider of the connection of a FlutterFire app:FirebaseAuthDart.userAuthFor(app)offirebase_auth_dart_platform, or aFlutterFireAuthTokenProviderofcloud_firestore_dart_flutterfire. Called when a client is created and thefirebase_app_dartapp of its FlutterFire app has no token provider yet: while it returns null, for every client created (each database, each new client after a delete); once it returned a provider, not again for thatfirebase_app_dartapp. The Dart core of Linux deletes that app with the FlutterFire app, so a delete and create calls it again; the native and web cores keep it, with its provider. Without it, or when it returns null, the connection carries no user. The provider is installed as aTokenOnChangeProvider, whose change events carry the token. Afirebase_app_dartapp that already exists with the name of the FlutterFire app keeps its own providers, and gets these only where it has none.appCheckProviderForreturns the App Check token provider of the connection of a FlutterFire app (FlutterFireAppCheckProviderofcloud_firestore_dart_flutterfirefor the officialfirebase_app_check). Called astokenProviderForis, when thefirebase_app_dartapp has no App Check provider yet.persistenceFormakes the clients keep their cache and pending writes on disk (see DatabasePersistenceFactory); without it every client is in memory.FirebaseDatabase.setPersistenceEnabled(false)turns it off for an instance;setPersistenceEnabled(true)without it prints a warning and stays in memory.useDartCorereplaces the implementation offirebase_corewith a small pure-Dart one, only whilefirebase_corehas its default method-channel implementation (a core another package installed is kept). By default (null) that happens only on Linux; pass true to do it on any platform (for example in tests), false to never do it.
Throws a StateError once an instance has created its client: the configuration is read then.
Implementation
static void use({
TokenProviderFactory? tokenProviderFor,
AppCheckProviderFactory? appCheckProviderFor,
DatabasePersistenceFactory? persistenceFor,
bool? useDartCore,
}) {
if (DartFirebaseDatabase.anyStarted) {
throw StateError(
'FirebaseDatabaseDart.use must be called before the first use of '
'FirebaseDatabase.',
);
}
DartFirebaseDatabase.config = DartDatabaseConfig(
tokenProviderFor: tokenProviderFor,
appCheckProviderFor: appCheckProviderFor,
persistenceFor: persistenceFor,
);
installCoreIfNeeded(force: useDartCore);
if (!isRegistered) {
final DartFirebaseDatabase platform = DartFirebaseDatabase();
DatabasePlatform.instance = platform;
_registered = platform;
}
}