FirebaseSyncAdapter class abstract
Firebase Firestore adapter stub.
To use: add cloud_firestore to your app's pubspec.yaml,
then implement the methods using the Firestore SDK.
import 'package:cloud_firestore/cloud_firestore.dart';
class MyFirebaseAdapter extends FirebaseSyncAdapter {
final FirebaseFirestore _firestore = FirebaseFirestore.instance;
@override
Future<SyncAdapterResult> push(SyncOperation operation) async {
final ref = _firestore.collection(operation.collection);
switch (operation.type) {
case OperationType.create:
final doc = await ref.add(operation.data);
return SyncAdapterResult.success({'id': doc.id, ...operation.data});
case OperationType.update:
await ref.doc(operation.recordId).update(operation.data);
return SyncAdapterResult.success(operation.data);
case OperationType.delete:
await ref.doc(operation.recordId).delete();
return SyncAdapterResult.success({});
default:
return SyncAdapterResult.success(operation.data);
}
}
// ... implement pull and pullAll
}
- Inheritance
-
- Object
- SyncAdapter
- FirebaseSyncAdapter
Constructors
- FirebaseSyncAdapter()
-
const
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
isReachable(
) → Future< bool> -
Check if the adapter can currently reach the server
inherited
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
pull(
String collection, String id) → Future< Map< String, dynamic> ?> -
Pull the latest server data for a record.
inherited
-
pullAll(
String collection) → Future< List< Map< >String, dynamic> > -
Pull all records for a collection (for initial sync / refresh)
inherited
-
push(
SyncOperation operation) → Future< SyncAdapterResult> -
Push a local operation to the server.
inherited
-
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited