pushDelta method
Future<void>
pushDelta({
- required String collection,
- required String recordId,
- required Map<
String, dynamic> delta, - required int baseVersion,
- required DateTime timestamp,
override
Push delta (partial update) to backend.
Only sends changed fields instead of the entire document, reducing bandwidth by up to 98%.
Parameters:
collection: Collection namerecordId: Document IDdelta: Only the fields that changedbaseVersion: Version before this updatetimestamp: When the update occurred
If the backend doesn't support delta sync, this should fall back to a regular push() with the full document.
Implementation
@override
Future<void> pushDelta({
required String collection,
required String recordId,
required Map<String, dynamic> delta,
required int baseVersion,
required DateTime timestamp,
}) async {
// Firebase Firestore supports partial updates natively
// We can use merge: true to only update changed fields
final updateData = <String, dynamic>{};
// Prefix each delta field with 'data.' for nested update
for (final entry in delta.entries) {
updateData['data.${entry.key}'] = entry.value;
}
updateData['updatedAt'] = Timestamp.fromDate(timestamp);
updateData['version'] = FieldValue.increment(1);
await firestore.collection(collection).doc(recordId).set(
updateData,
SetOptions(merge: true),
);
}