limitToLast method
Creates and returns a new Query that only returns the last matching documents up to the specified number. This
overrides a previous limit.
You must specify at least one orderBy clause for limitToLast queries, otherwise a StateError is thrown when the query is executed (get fails with it, snapshots throws it). The results are returned in the order of the query (not reversed).
limit the maximum number of items to return. Throws an ArgumentError if it is not positive.
Returns the created Query.
// The three cities with the largest population, smallest first.
final QuerySnapshot<Map<String, Object?>> lastThree = await firestore
.collection('cities')
.orderBy('population')
.limitToLast(3)
.get();
Implementation
Query<T> limitToLast(int limit) {
return _withQuery(_builder.limitToLast(query, limit));
}