shelfPaginate function
Middleware
shelfPaginate(
{ - int limit = 10,
- int maxLimit = 50,
})
Implementation
Middleware shelfPaginate({int limit = 10, int maxLimit = 50}) {
return (Handler innerHandle) {
return (request) {
return Future.sync(() => innerHandle(request)).then((response) {
if (request.headers.containsKey('x-paginate') &&
(request.headers['x-paginate']!.toLowerCase() == 'true')) {
return _paginate(
response,
int.tryParse(request.url.queryParameters['page'] ?? 'page') ?? 1,
int.tryParse(request.url.queryParameters['limit'] ?? 'limit') ?? limit,
maxLimit,
);
}
return response;
});
};
};
}