paginate method

  1. @override
Future<Chunk<T>> paginate(
  1. Chunk<T> chunk
)
override

Get a number of Documents from the Collection specified by the chunk

Store the Chunk you get back from calling this method and pass it back to the paginate method to get the next Chunk

You can continue to do this until the Chunk.status equals ChunkStatus.last.

Passing in a Chunk with the status of ChunkStatus.last will result in a Chunk with empty data.

Implementation

@override
Future<Chunk<T>> paginate(Chunk<T> chunk) async {
  final snapshot = await _buildPaginationSnapshot(chunk);

  final data = snapshot.docs.toListT();
  final cursor = snapshot.size == 0 ? null : snapshot.docs.last;

  final snapshotLength = snapshot.docs.length;
  final isNotLast = snapshotLength == chunk.limit;

  return isNotLast
      ? Chunk<T>.next(
          data: data,
          cursor: cursor,
          orderBy: chunk.orderBy,
        )
      : Chunk<T>.last(
          data: data,
          cursor: cursor,
          orderBy: chunk.orderBy,
        );
}