startAfterDocument method
Creates and returns a new Query that starts after the provided document (exclusive). The starting position is relative to the order of the query. The document must contain all of the fields provided in the orderBy of this query.
snapshot the snapshot of the document to start after.
Returns the created Query.
This is how you page through results: start the next page after the last document of the previous one. Throws an ArgumentError in the cases described in startAtDocument.
final Query<Map<String, Object?>> byName = firestore
.collection('cities')
.orderBy('name')
.limit(25);
final QuerySnapshot<Map<String, Object?>> first = await byName.get();
if (first.isNotEmpty) {
final QuerySnapshot<Map<String, Object?>> second = await byName
.startAfterDocument(first.last)
.get();
print(second.length);
}
Implementation
Query<T> startAfterDocument(DocumentSnapshot<Object?> snapshot) {
checkNotNull<DocumentSnapshot<Object?>>(
snapshot,
'Provided snapshot must not be null.',
);
final Bound bound = _builder.boundFromDocument(
query,
'startAfter',
snapshot.document,
inclusive: false,
);
return _withQuery(query.startAt(bound));
}