paginateCollection method

Future<List<QueryDocumentSnapshot<Object?>>> paginateCollection(
  1. String collectionPath, {
  2. DocumentSnapshot<Object?>? startAfter,
  3. int limit = 10,
})

Implementation

Future<List<QueryDocumentSnapshot>> paginateCollection(String collectionPath,
    {DocumentSnapshot? startAfter, int limit = 10}) async {
  Query query = _db.collection(collectionPath).limit(limit);
  if (startAfter != null) {
    query = query.startAfterDocument(startAfter);
  }
  QuerySnapshot querySnapshot = await query.get();
  return querySnapshot.docs;
}