firebase_database_rest
REST 기반의 플랫폼 독립적인 Dart/Flutter 래퍼로 Firebase 실시간 데이터베이스 API를 사용합니다.
REST 기반의 플랫폼 독립적인 Firebase Realtime Database API용 Dart/Flutter 래퍼
^2.0.1^0.14.1^0.13.3^4.0.1^1.3.0^1.8.0^2.0.2^1.0.2^2.3.0^0.14.1+3^4.1.1^1.5.3^0.1.2^1.17.3^0.4.0^2.0.0아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.
Continous Integration Pub Version
A platform independent Dart/Flutter Wrapper for the Firebase Realtime Database API based on REST
firebase_database_rest/rest.dart)Simply add firebase_database_rest to your pubspec.yaml and run pub get (or flutter pub get).
The libraries primary class is the FirebaseStore. It is a high-level class that allows access to a certain part of the realtime database using Model binding.
With this store, you specify a subpatch and can then perform various operations on elements below that path (list key, create, read, write or delete them, ...).
This class also provides the APIs for streaming changes and transactions. Typically, your application would use multiple stores, one for each dataclass you plan
to store at a certain path.
The second important class is the FirebaseDatabase. It serves as the toplevel class, parent to all stores and manages the database connection itself, including
the management of the associated FirebaseAccount (from firebase_auth_rest) and background ressources
(like the REST-API interface).
The following code is a simple example, which can be found in full length, including errorhandling, at https://pub.dev/packages/firebase_database_rest/example. It loggs into firebase as anonymous user, starts streaming changes and then does some db operations.
// The data class that is stored in firebase
class ExampleModel {
final int id;
final String data;
const ExampleModel(this.id, this.data);
// ...
}
// obtain a firebase account, using firebase_auth_rest
final account = // ...
// create a database reference from that account
final database = FirebaseDatabase(
account: account,
database: 'my-firebase-realtime-database-name,
basePath: 'application/${account.localId}/example',
);
// create typed store. In this example, a callback store is used, but you can
// also just extend FirebaseStore
final store = database.createRootStore<ExampleModel>(
onDataFromJson: (dynamic json) => ExampleModel.fromJson(json),
onDataToJson: (data) => data.toJson(),
onPatchData: (data, updatedFields) => data.patch(updatedFields),
);
// add a stream listener that reports database changes in realtime
sub = (await store.streamAll()).listen((e) => print('Stream update: $e'));
// add some data to the store
await store.create(const ExampleModel(1, 'A'));
// get all data in store
print('All data: ${await store.all()}');
// cleanup: stop streaming and dispose of the database
await sub.cancel();
await database.dispose();
The documentation is available at https://pub.dev/documentation/firebase_database_rest/latest/. A full example can be found at https://pub.dev/packages/firebase_database_rest/example.