paginate method

List<E> paginate(
  1. int page,
  2. int itemsPerPage
)

Pagination: If you're working with paginated data, you can create custom extensions to handle pagination-related operations.

Implementation

List<E> paginate(int page, int itemsPerPage) {
  final startIndex = (page - 1) * itemsPerPage;
  final endIndex = startIndex + itemsPerPage;
  if (startIndex >= length) return [];
  return sublist(startIndex, endIndex.clamp(0, length));
}