getCursorPage method
Implementation
BlocxPage<T> getCursorPage({String? cursor, required int limit}) {
final startIndex = cursor != null ? int.tryParse(cursor) ?? 0 : 0;
final clampedStart = startIndex.clamp(0, items.length);
final endIndex = (clampedStart + limit).clamp(0, items.length);
final pageItems = items.sublist(clampedStart, endIndex);
final nextCursor = endIndex < items.length ? endIndex.toString() : null;
return BlocxPage<T>(
items: pageItems,
offset: clampedStart,
limit: limit,
nextCursor: nextCursor,
hasNext: nextCursor != null,
);
}