QuerySnapshot<T extends dynamic> class

A QuerySnapshot contains the results of a query. It can contain zero or more DocumentSnapshot objects.

It is an Iterable of QueryDocumentSnapshots in the order of the query, so you can loop over it directly; docs gives them as a list and docChanges lists what changed since the previous snapshot of the same listener. metadata tells whether the results came from the local cache and whether they include local writes that the backend has not acknowledged yet.

final QuerySnapshot<Map<String, Object?>> snapshot = await firestore
    .collection('cities')
    .where('state', isEqualTo: 'CA')
    .get();
print('${snapshot.length} cities, from cache: ${snapshot.metadata.isFromCache}');
for (final QueryDocumentSnapshot<Map<String, Object?>> city in snapshot) {
  print('${city.id}: ${city.data()}');
}

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

Constructors

QuerySnapshot.fromJson(FirebaseFirestore firestore, Map<String, Object?> json, {FirestoreDataConverter<T>? converter})
Builds a QuerySnapshot from the JSON object written by toJson, for the firestore instance.
factory

Properties

docChanges → List<DocumentChange<T>>
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.
no setter
docs → List<QueryDocumentSnapshot<T>>
Returns the documents in this QuerySnapshot as a List in order of the query. Same as docs but typed as QueryDocumentSnapshot; this is the name used by the current official Firestore API.
no setter
first → QueryDocumentSnapshot<T>
The first element.
no setterinherited
hashCode → int
The hash code for this object.
no setteroverride
isEmpty → bool
Returns true if there are no documents in the QuerySnapshot.
no setteroverride
isNotEmpty → bool
Whether this collection has at least one element.
no setterinherited
iterator → Iterator<QueryDocumentSnapshot<T>>
Iterates over the documents of this snapshot in the order of the query.
no setteroverride
last → QueryDocumentSnapshot<T>
The last element.
no setterinherited
length → int
The number of documents in the QuerySnapshot.
no setteroverride
metadata → SnapshotMetadata
The metadata of this query snapshot: whether the results came from the cache (SnapshotMetadata.isFromCache) and whether one of the documents has local writes that the backend has not acknowledged yet (SnapshotMetadata.hasPendingWrites).
final
query → Query<T>
The query whose results this snapshot holds.
final
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited
single → QueryDocumentSnapshot<T>
Checks that this iterable has only one element, and returns that element.
no setterinherited
size → int
The number of documents in the QuerySnapshot: the FlutterFire and JS SDK name of length.
no setter

Methods

any(bool test(QueryDocumentSnapshot<T> element)) → bool
Checks whether any element of this iterable satisfies test.
inherited
cast<R>() → Iterable<R>
A view of this iterable as an iterable of R instances.
inherited
contains(Object? element) → bool
Whether the collection contains an element equal to element.
inherited
elementAt(int index) → QueryDocumentSnapshot<T>
Returns the indexth element.
inherited
every(bool test(QueryDocumentSnapshot<T> element)) → bool
Checks whether every element of this iterable satisfies test.
inherited
expand<T>(Iterable<T> toElements(QueryDocumentSnapshot<T> element)) → Iterable<T>
Expands each element of this Iterable into zero or more elements.
inherited
firstWhere(bool test(QueryDocumentSnapshot<T> element), {QueryDocumentSnapshot<T> orElse()?}) → QueryDocumentSnapshot<T>
The first element that satisfies the given predicate test.
inherited
fold<T>(T initialValue, T combine(T previousValue, QueryDocumentSnapshot<T> element)) → T
Reduces a collection to a single value by iteratively combining each element of the collection with an existing value
inherited
followedBy(Iterable<QueryDocumentSnapshot<T>> other) → Iterable<QueryDocumentSnapshot<T>>
Creates the lazy concatenation of this iterable and other.
inherited
forEach(void action(QueryDocumentSnapshot<T> element)) → void
Invokes action on each element of this iterable in iteration order.
inherited
join([String separator = ""]) → String
Converts each element to a String and concatenates the strings.
inherited
lastWhere(bool test(QueryDocumentSnapshot<T> element), {QueryDocumentSnapshot<T> orElse()?}) → QueryDocumentSnapshot<T>
The last element that satisfies the given predicate test.
inherited
map<T>(T toElement(QueryDocumentSnapshot<T> e)) → Iterable<T>
The current elements of this iterable modified by toElement.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
reduce(QueryDocumentSnapshot<T> combine(QueryDocumentSnapshot<T> value, QueryDocumentSnapshot<T> element)) → QueryDocumentSnapshot<T>
Reduces a collection to a single value by iteratively combining elements of the collection using the provided function.
inherited
singleWhere(bool test(QueryDocumentSnapshot<T> element), {QueryDocumentSnapshot<T> orElse()?}) → QueryDocumentSnapshot<T>
The single element that satisfies test.
inherited
skip(int count) → Iterable<QueryDocumentSnapshot<T>>
Creates an Iterable that provides all but the first count elements.
inherited
skipWhile(bool test(QueryDocumentSnapshot<T> element)) → Iterable<QueryDocumentSnapshot<T>>
Creates an Iterable that skips leading elements while test is satisfied.
inherited
take(int count) → Iterable<QueryDocumentSnapshot<T>>
Creates a lazy iterable of the count first elements of this iterable.
inherited
takeWhile(bool test(QueryDocumentSnapshot<T> element)) → Iterable<QueryDocumentSnapshot<T>>
Creates a lazy iterable of the leading elements satisfying test.
inherited
toJson() → Map<String, Object?>
Returns a JSON-serializable representation of this snapshot, which QuerySnapshot.fromJson reads back and FirebaseFirestore.querySnapshotsFromJson listens from.
toList({bool growable = true}) → List<QueryDocumentSnapshot<T>>
Creates a List containing the elements of this Iterable.
inherited
toSet() → Set<QueryDocumentSnapshot<T>>
Creates a Set containing the same elements as this iterable.
inherited
toString() → String
Returns a string representation of (some of) the elements of this.
override
where(bool test(QueryDocumentSnapshot<T> element)) → Iterable<QueryDocumentSnapshot<T>>
Creates a new lazy Iterable with all elements that satisfy the predicate test.
inherited
whereType<T>() → Iterable<R>
Creates a new lazy Iterable with all elements that have type T.
inherited

Operators

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

Constants

jsonType → const String
The value of the type field written by toJson.