Skip to main content

firebase_database_dart_platform 0.1.0 copy "firebase_database_dart_platform: ^0.1.0" to clipboard
firebase_database_dart_platform: ^0.1.0 copied to clipboard

Unofficial pure-Dart implementation of the FlutterFire Realtime Database platform interface: the official firebase_database API on Linux, or on any platform you choose.

example/main.dart

// A Flutter program that uses the official firebase_database API, with
// firebase_database_dart doing the work underneath.
//
// On Linux the FirebaseDatabaseDart.use() call is optional: Flutter registers
// the package before main() runs. On the other platforms it replaces the
// official implementation. Run it against a Database emulator on
// 127.0.0.1:9100 with open rules for this namespace (in a checkout of the
// repository: `tool/start_database_emulator.sh 9100` from its root).

import 'dart:async';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_database/firebase_database.dart';
import 'package:firebase_database_dart_platform/firebase_database_dart_platform.dart';
import 'package:flutter/widgets.dart';

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  FirebaseDatabaseDart.use();
  await Firebase.initializeApp(
    // Use your own options (flutterfire configure) for a real project.
    options: const FirebaseOptions(
      apiKey: 'demo-api-key',
      appId: '1:1:web:1',
      messagingSenderId: '1',
      projectId: 'demo-test',
      databaseURL: 'https://demo-test-default-rtdb.firebaseio.com',
    ),
  );
  final FirebaseDatabase database = FirebaseDatabase.instance;
  database.useDatabaseEmulator('127.0.0.1', 9100);

  final DatabaseReference notes = database.ref('notes');
  final StreamSubscription<DatabaseEvent> added = notes.onChildAdded.listen((
    DatabaseEvent event,
  ) {
    debugPrint('added ${event.snapshot.key}: ${event.snapshot.value}');
  });
  await notes.push().set(<String, Object?>{
    'text': 'Hello from Dart',
    'createdAt': ServerValue.timestamp,
  });

  final DatabaseReference likes = database.ref('counters/likes');
  final TransactionResult result = await likes.runTransaction(
    (Object? value) => Transaction.success(((value as int?) ?? 0) + 1),
  );
  debugPrint('likes: ${result.snapshot.value} (${result.committed})');

  final DatabaseReference status = database.ref('status/example');
  await status.onDisconnect().set('offline');
  await status.set('online');

  final DataSnapshot all = await notes.get();
  debugPrint('${all.children.length} notes');
  await added.cancel();
}
0
likes
160
points
--
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Unofficial pure-Dart implementation of the FlutterFire Realtime Database platform interface: the official firebase_database API on Linux, or on any platform you choose.

Homepage
Repository (GitHub)
View/report issues

Topics

#firebase #database #flutterfire #linux

License

Apache-2.0 (license)

Dependencies

firebase_app_dart, firebase_core, firebase_core_platform_interface, firebase_database_dart, firebase_database_platform_interface, flutter

More

Packages that depend on firebase_database_dart_platform

Packages that implement firebase_database_dart_platform