DocumentChange<T extends dynamic> class

A DocumentChange represents a change to the documents matching a query. It contains the document affected and the type of change that occurred (added, modified, or removed).

You get the changes of a snapshot from QuerySnapshot.docChanges. Applying them in order to the documents of the previous snapshot gives the documents of the new one; oldIndex and newIndex say where each change applies, for example to update a list in a user interface.

final List<QueryDocumentSnapshot<Map<String, Object?>>> rows = [];
firestore.collection('cities').orderBy('name').snapshots().listen((
  QuerySnapshot<Map<String, Object?>> snapshot,
) {
  for (final DocumentChange<Map<String, Object?>> change
      in snapshot.docChanges) {
    if (change.oldIndex != -1) {
      rows.removeAt(change.oldIndex);
    }
    if (change.newIndex != -1) {
      rows.insert(change.newIndex, change.doc);
    }
  }
});

Subclassing Note: Firestore classes are not meant to be subclassed except for use in test mocks. Subclassing is not supported in production code and new SDK releases may break code that does so.

Properties

doc → QueryDocumentSnapshot<T>
Returns the newly added or modified document if this DocumentChange is for an updated document. Returns the deleted document if this document change represents a removal.
final
hashCode → int
The hash code for this object.
no setteroverride
newIndex → int
The index of the changed document in the result set immediately after this DocumentChange (i.e. supposing that all prior DocumentChange objects and the current DocumentChange object have been applied). Returns -1 for 'removed' events.
final
oldIndex → int
The index of the changed document in the result set immediately prior to this DocumentChange (i.e. supposing that all prior DocumentChange objects have been applied). Returns -1 for 'added' events.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
type → DocumentChangeType
The kind of change: DocumentChangeType.added, DocumentChangeType.modified or DocumentChangeType.removed.
final

Methods

noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toString() → String
A string representation of this object.
override

Operators

operator ==(Object other) → bool
The equality operator.
override