docChanges property
List<DocumentChange<T> >
get
docChanges
The documents that changed since the previous snapshot of the same listener, in the order the changes apply. In the first snapshot every document is a DocumentChangeType.added change.
When the listener was started with snapshots(includeMetadataChanges: true), a document whose metadata only
changed is in the list too, as a DocumentChangeType.modified change; otherwise such documents are not
included.
firestore.collection('cities').snapshots().listen((
QuerySnapshot<Map<String, Object?>> snapshot,
) {
for (final DocumentChange<Map<String, Object?>> change
in snapshot.docChanges) {
switch (change.type) {
case DocumentChangeType.added:
print('new city: ${change.doc.data()}');
case DocumentChangeType.modified:
print('modified city: ${change.doc.data()}');
case DocumentChangeType.removed:
print('removed city: ${change.doc.id}');
}
}
});
Implementation
List<DocumentChange<T>> get docChanges {
return _cachedChanges ??= DocumentChangeInternal.changesFromSnapshot<T>(
_firestore,
snapshot.excludesMetadataChanges
? MetadataChanges.exclude
: MetadataChanges.include,
snapshot,
query.converter,
).toList(growable: false);
}