PaginationResponse<T> class

Generic pagination response wrapper

This class can adapt to different API response formats by using custom extractors for data, total count, and pagination metadata.

Examples:

DummyJSON-style APIs:

final response = PaginationResponse.fromJson(
  json,
  Product.fromJson,
  dataExtractor: (json) => json['products'] as List<dynamic>,
  totalExtractor: (json) => json['total'] as int,
  skipExtractor: (json) => json['skip'] as int,
  limitExtractor: (json) => json['limit'] as int,
);

Standard REST APIs:

final response = PaginationResponse.fromJson(
  json,
  User.fromJson,
  dataExtractor: (json) => json['data'] as List<dynamic>,
  totalExtractor: (json) => json['total'] as int,
);

Constructors

PaginationResponse.new({required List<T> items, required int total, required int skip, required int limit, required bool isLastPage, dynamic nextPageKey})
const
PaginationResponse.empty()
Creates an empty PaginationResponse
factory
PaginationResponse.fromCursorBased(Map<String, dynamic> json, T itemFromJson(Map<String, dynamic>), {String dataKey = 'data', String paginationKey = 'pagination', String nextCursorKey = 'next_cursor', String hasMoreKey = 'has_more'})
Creates a PaginationResponse for cursor-based pagination
factory
PaginationResponse.fromDummyJson(Map<String, dynamic> json, T itemFromJson(Map<String, dynamic>), String dataKey)
Creates a PaginationResponse for DummyJSON-style APIs
factory
PaginationResponse.fromJson(Map<String, dynamic> json, T itemFromJson(Map<String, dynamic>), {List dataExtractor(Map<String, dynamic>)?, int totalExtractor(Map<String, dynamic>)?, int skipExtractor(Map<String, dynamic>)?, int limitExtractor(Map<String, dynamic>)?, dynamic nextPageKeyExtractor(Map<String, dynamic>)?})
Creates a PaginationResponse from JSON with custom extractors
factory
PaginationResponse.fromLaravel(Map<String, dynamic> json, T itemFromJson(Map<String, dynamic>))
Creates a PaginationResponse for Laravel-style pagination
factory
PaginationResponse.fromList(List<T> items)
Creates a single-page PaginationResponse from a list of items
factory
PaginationResponse.fromPageBased(Map<String, dynamic> json, T itemFromJson(Map<String, dynamic>), {String dataKey = 'data', String currentPageKey = 'current_page', String lastPageKey = 'last_page', String perPageKey = 'per_page', String totalKey = 'total'})
Creates a PaginationResponse for page-based pagination
factory

Properties

currentPage int
The current page number (1-based)
no setter
hashCode int
The hash code for this object.
no setteroverride
hasNextPage bool
Whether there are more pages available
no setter
hasPreviousPage bool
Whether there are previous pages available
no setter
isLastPage bool
Whether this is the last page
final
itemRange String
The range of items on the current page (e.g., "1-10 of 100")
no setter
items List<T>
The list of items for the current page
final
limit int
Number of items per page
final
nextPageKey → dynamic
Next page key (can be page number, cursor, or offset)
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
skip int
Current skip/offset value
final
total int
Total number of items available (across all pages)
final
totalPages int
The total number of pages
no setter

Methods

copyWith({List<T>? items, int? total, int? skip, int? limit, bool? isLastPage, dynamic nextPageKey}) PaginationResponse<T>
Returns a copy of this pagination response with updated values
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toJson(Map<String, dynamic> itemToJson(T)) Map<String, dynamic>
Converts this pagination response to JSON
toString() String
A string representation of this object.
override

Operators

operator ==(Object other) bool
The equality operator.
override