QueryDocumentSnapshot<T extends dynamic> class

A QueryDocumentSnapshot contains data read from a document in your Firestore database as part of a query. The document is guaranteed to exist and its data can be extracted using the data or get methods.

QueryDocumentSnapshot offers the same API surface as DocumentSnapshot. Since query results contain only existing documents, the exists method will always return true and data will never be null.

You get them by iterating a QuerySnapshot (or from its docs) and from DocumentChange.document.

final QuerySnapshot<Map<String, Object?>> snapshot = await firestore
    .collection('cities')
    .get();
for (final QueryDocumentSnapshot<Map<String, Object?>> doc in snapshot) {
  final Map<String, Object?> data = doc.data(); // never null
  print('${doc.id}: ${data['name']}');
}

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.

Inheritance

Properties

exists → bool
Returns true if the document existed in this snapshot.
no setterinherited
hashCode → int
The hash code for this object.
no setterinherited
id → String
The id of the document: the last segment of its path.
no setterinherited
metadata → SnapshotMetadata
The metadata for this document snapshot: whether it came from the cache (SnapshotMetadata.isFromCache) and whether it has local writes that the backend has not acknowledged yet (SnapshotMetadata.hasPendingWrites).
finalinherited
reference → DocumentReference<T>
The reference to the document, with the converter of this snapshot.
no setterinherited
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

contains(Object field) → bool
Whether the field exists in the document, also when its value is null. False if the document does not exist.
inherited
data({ServerTimestampBehavior serverTimestamps = ServerTimestampBehavior.none}) → T
The fields of the document, or the converted T with a converter. Unlike DocumentSnapshot.data() it is never null for a snapshot without a converter: the document exists.
override
get(Object field, {ServerTimestampBehavior serverTimestamps = ServerTimestampBehavior.none}) → Object?
The value of field, or null if the field or the document doesn't exist.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson() → Map<String, Object?>
Returns a JSON-serializable representation of this snapshot, which DocumentSnapshot.fromJson reads back and FirebaseFirestore.documentSnapshotsFromJson listens from.
inherited
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited
operator [](Object field) → Object?
The value of field, or null if the field or the document does not exist. Same as get.
inherited