firebase_database_dart_platform library

An implementation of FlutterFire's Realtime Database platform interface on top of the pure-Dart client firebase_database_dart.

An app keeps the official firebase_database API (FirebaseDatabase.instance.ref('notes').onValue), and firebase_database_dart does the work underneath, over the Realtime Database WebSocket protocol:

  • On Linux, where neither firebase_database nor firebase_core has an implementation, adding this package is enough: Flutter calls FirebaseDatabaseDart.registerWith before main. That registration has no token provider and no persistence: the connection carries no user and keeps its data in memory, unless main calls FirebaseDatabaseDart.use with them before the first use.
  • On Windows, the same when the app lists this package as a direct dependency: it replaces the native firebase_database plugin.
  • On any other platform, call FirebaseDatabaseDart.use at the start of main, before the first use of Firebase, to replace the official implementation.
Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  FirebaseDatabaseDart.use(
    tokenProviderFor: (FirebaseApp app) => FirebaseAuthDart.userAuthFor(app),
  );
  await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
  await FirebaseDatabase.instance.ref('notes/today').set('Hello');
}

Classes

DartFirebaseDatabase
The implementation of DatabasePlatform on top of firebase_database_dart: one instance per FlutterFire app and database (see forApp).
FirebaseDatabaseDart
Selects firebase_database_dart as the implementation of the official firebase_database package.

Typedefs

AppCheckProviderFactory = AppCheckTokenProvider? Function(FirebaseApp app)
Returns the App Check token provider of the Realtime Database connection of the FlutterFire app, or null for a connection without an App Check token.
DatabasePersistenceFactory = DatabasePersistence Function(int cacheSizeBytes)
Returns the persistence of the clients of this package, for the cache size the app set with FirebaseDatabase.setPersistenceCacheSizeBytes (10 MiB when it set none), for example (int cacheSizeBytes) => sqlitePersistence(directory, cacheSizeBytes: cacheSizeBytes) of firebase_database_dart_sqlite.
TokenProviderFactory = AuthTokenProvider? Function(FirebaseApp app)
Returns the token provider that the Realtime Database connection of the FlutterFire app authenticates with, or null for a connection without a user.