smart_pagination_pro 1.0.3
smart_pagination_pro: ^1.0.3 copied to clipboard
Production-ready Flutter pagination package with infinite scroll, scroll pagination, load more, async/API pagination, Page, Offset, and Cursor strategies, search debouncing, filters, sorting, refresh, [...]
Smart Pagination Pro π #
Production-ready Flutter pagination framework for Infinite Scroll, Scroll Pagination, Load More, API Pagination and more.
β¨ Key Features #
- βΎοΈ Infinite Scroll Pagination: Automatically fetch the next page as the user scrolls near the bottom.
- π Scroll Pagination: Seamless scroll-based pagination with automatic viewport prefetching.
- π Load More Pagination: Smooth pagination with inline footer load-more state and manual retry capability.
- π Async / API Pagination: Connect to any REST API, GraphQL query, Firebase Firestore, SQLite, or custom backend.
- π Page-based Pagination: Standard page number strategy (
?page=1&pageSize=20). - π Offset-based Pagination: Record offset strategy (
?offset=20&limit=20). - π― Cursor-based Pagination: Keyset/cursor token strategy (
?cursor=abc123&limit=20). - π Search with Debouncing: Real-time async search query debouncing (
searchDebounceDuration) with automatic pagination reset. - ποΈ Filters: Apply single or multiple key-value filters (
setFilter,setFilters,clearFilters). - βοΈ Sorting: Sort fields in ascending or descending order (
SmartSort). - π Pull-to-Refresh: Native pull-to-refresh integration keeping search, filter, and sort criteria intact.
- β‘ Configurable Prefetching: Prefetch the next page before reaching the bottom (
prefetchDistance: 500). - π‘οΈ Race-Condition Protection: Generation token tracking prevents out-of-order API responses from overwriting newer data.
- π« Duplicate Request Protection: Deduplicates concurrent requests for identical query parameter keys.
- π Shimmer Loading: Built-in, zero-dependency skeleton shimmer loader (
SmartShimmer,showShimmer: true). - β Error & Retry States: Graceful error catching and retries without clearing existing data.
- π± Responsive Mobile / Tablet / Desktop / Web: Adaptive list, grid, and pagination bar layouts.
- π Light & Dark Theme: Inherits
Theme.of(context)with full dark mode support. - π Paginated List:
SmartPaginatedListwith scroll listeners, pull-to-refresh, and customizable builders. - π² Paginated Grid:
SmartPaginatedGridwith adaptive cross-axis layout.
π¦ Installation #
Add smart_pagination_pro to your pubspec.yaml:
dependencies:
smart_pagination_pro: ^1.0.3
π Quick Start #
1. Beginner-Friendly Simple API #
For standard use cases, SmartPaginatedList.simple handles controller creation, lifecycle, and scroll listening automatically:
import 'package:flutter/material.dart';
import 'package:smart_pagination_pro/smart_pagination_pro.dart';
class SimpleUserList extends StatelessWidget {
const SimpleUserList({super.key});
@override
Widget build(BuildContext context) {
return SmartPaginatedList<User>.simple(
pageSize: 20,
showShimmer: true,
fetch: (request) async {
final response = await userApi.getUsers(
page: request.page,
limit: request.pageSize,
);
return SmartPageResult<User>(
items: response.users,
totalItems: response.total,
);
},
itemBuilder: (context, user, index) {
return ListTile(
title: Text(user.name),
subtitle: Text(user.email),
);
},
);
}
}
2. Advanced Controller Architecture #
For full control over search, multi-filtering, sorting, or custom state management:
class AdvancedPatientDirectory extends StatefulWidget {
const AdvancedPatientDirectory({super.key});
@override
State<AdvancedPatientDirectory> createState() => _AdvancedPatientDirectoryState();
}
class _AdvancedPatientDirectoryState extends State<AdvancedPatientDirectory> {
late final SmartPaginationController<Patient> controller;
@override
void initState() {
super.initState();
controller = SmartPaginationController<Patient>(
pageSize: 20,
strategy: PaginationStrategy.page,
prefetchDistance: 500,
autoFillViewport: true,
deduplicateItems: true,
itemKey: (patient) => patient.id,
fetch: (request) async {
final response = await api.getPatients(
page: request.page,
limit: request.pageSize,
search: request.search,
department: request.filters['department'],
sort: request.sort?.field,
);
return SmartPageResult(
items: response.items,
totalItems: response.totalCount,
);
},
);
controller.loadInitial();
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Column(
children: [
// Search Input
TextField(
decoration: const InputDecoration(hintText: 'Search patients...'),
onChanged: (query) => controller.search(query),
),
// Filter Dropdown
DropdownButton<String>(
hint: const Text('Filter Department'),
onChanged: (dept) => controller.setFilter('department', dept),
items: const [
DropdownMenuItem(value: 'Cardiology', child: Text('Cardiology')),
DropdownMenuItem(value: 'Neurology', child: Text('Neurology')),
],
),
// Responsive List View
Expanded(
child: SmartPaginatedList<Patient>(
controller: controller,
showShimmer: true,
itemBuilder: (context, patient, index) {
return PatientCard(patient: patient);
},
),
),
],
);
}
}
βΎοΈ Infinite Scroll #
Smart Pagination Pro automatically requests the next page while the user approaches the end of the scrollable viewport.
SmartPaginatedList<Article>(
controller: controller,
displayMode: PaginationDisplayMode.infiniteScroll,
itemBuilder: (context, article, index) => ArticleTile(article: article),
)
Key Infinite Scroll Capabilities: #
- Automatic Prefetching: Triggers
loadNextPage()when the scroll position reachesprefetchDistance(default500.0logical pixels before the bottom). - Viewport Auto-Fill: Automatically loads additional pages if initial results don't fill the viewport (
autoFillViewport: true, bounded bymaxAutoFillPages). - Last Page Detection: Intelligently determines when no more data exists based on
hasMore,nextCursor, ortotalItems. - Duplicate Request Guard: Deduplicates rapid scroll events so
loadNextPage()is only called once per page key. - Inline Load More Footer: Shows progress, error retry, or "You've reached the end" message at the bottom.
π Scroll Pagination & Load More #
Smart Pagination Pro provides three flexible presentation patterns:
- Infinite Scroll: Pages load automatically as the user scrolls near the bottom.
- Scroll Pagination: Page numbers and range counts appear in an adaptive bottom bar (
SmartPaginationBar). - Manual Load More: Configure custom footers or button triggers using
loadMoreErrorBuilderandloadingMoreBuilder.
π Pagination Strategies #
Smart Pagination Pro supports all 3 major API pagination strategies:
1. Page-based Pagination #
Used when APIs expect page numbers (page=1, page=2).
SmartPaginationController<Item>(
strategy: PaginationStrategy.page,
initialPage: 1, // Supports 1-based or 0-based initial page
pageSize: 20,
fetch: (request) async => api.getItems(page: request.page, size: request.pageSize),
);
2. Offset-based Pagination #
Used when APIs expect record offsets (offset=0, offset=20).
SmartPaginationController<Item>(
strategy: PaginationStrategy.offset,
initialOffset: 0,
pageSize: 20,
fetch: (request) async => api.getItems(offset: request.offset, limit: request.pageSize),
);
3. Cursor-based Pagination #
Used for keyset pagination where backend returns an opaque cursor token (nextCursor).
SmartPaginationController<Item>(
strategy: PaginationStrategy.cursor,
pageSize: 20,
fetch: (request) async {
final res = await api.getItems(cursor: request.cursor, limit: request.pageSize);
return SmartPageResult(items: res.items, nextCursor: res.nextCursorToken);
},
);
π Search + Pagination #
Built-in search with automatic debouncing, query token protection, and pagination reset:
// Triggers debounced search (default 400ms delay)
controller.search('Flutter');
// Resets pagination, invalidates pending queries, and fetches Page 1
Race-Condition Protection #
If rapid queries ("r" -> "ra" -> "ravi") complete out of order, the RequestCoordinator generation token discards stale responses, guaranteeing only the newest query results appear on screen.
π± Responsive UI #
Smart Pagination Pro adapts smoothly across Mobile, Tablet, Desktop, and Web:
SmartPaginatedList<T>: PaginatedListViewsupporting infinite scroll, pull-to-refresh, custom item builders, and dividers.SmartPaginatedGrid<T>: ResponsiveGridViewwithmaxCrossAxisExtentor fixedcrossAxisCount.SmartPaginationBar<T>: Responsive bar withPaginationLayout.auto(switches betweencompactmobile layout,standardtablet layout, andexpandeddesktop layout with page-size selector).
π¨ UI States #
Smart Pagination Pro manages all standard asynchronous state transitions:
| State | Visual Behavior |
|---|---|
| Initial Loading | Renders SmartShimmerList or CircularProgressIndicator |
| Success | Renders non-empty paginated item list or grid |
| Loading More | Keeps existing items visible; displays inline loader footer |
| Refreshing | Keeps existing items visible; triggers pull-to-refresh spinner |
| Empty State | Displays customizable empty state view (emptyBuilder) |
| Error State | Displays customizable error view (errorBuilder) with Retry button |
| End of List | Displays "You've reached the end" footer indicator |
ποΈ State Management Integration #
smart_pagination_pro does not enforce BLoC, Provider, Riverpod, or GetX. SmartPaginationController<T> extends Flutter's ChangeNotifier and implements ValueListenable<SmartPaginationState<T>>.
BLoC / Cubit Integration Example #
class PatientCubit extends Cubit<SmartPaginationState<Patient>> {
PatientCubit(this.api) : super(SmartPaginationState.initial(initialPage: 1, initialOffset: 0, pageSize: 20)) {
controller = SmartPaginationController<Patient>(
pageSize: 20,
fetch: (req) => api.fetchPatients(req),
onStateChanged: (newState) => emit(newState),
);
}
final PatientApi api;
late final SmartPaginationController<Patient> controller;
@override
Future<void> close() {
controller.dispose();
return super.close();
}
}
π API Reference #
Core Classes & Exports #
SmartPaginationController<T>: Main controller for triggering queries, resets, searches, filters, sorting, and state updates.SmartPaginationState<T>: Immutable state containingitems,status,currentPage,currentOffset,pageSize,totalItems,hasMore,search,filters,sort,nextCursor, anderror.SmartPaginationRequest: Request parameters model passed intofetch.SmartPageResult<T>: Result payload returned by user data source fetch functions.SmartPaginatedList<T>: Paginated list widget.SmartPaginatedGrid<T>: Paginated grid widget.SmartPaginationBar<T>: Material 3 responsive pagination bar widget.SmartShimmer: Built-in zero-dependency shimmer animation wrapper.
π License #
MIT License. Free to use in commercial and open-source applications.