- A Flutter application showcasing pagination implementation using the
flutter_bloc
library. This project demonstrates how to efficiently load and display data in chunks, providing a smooth user experience with minimal resource consumption.
-
Pagination with Cubit: Utilize the power of flutter_bloc for efficient state management in paginated scenarios.
-
Efficient Data Loading: Load data in chunks to minimize the impact on performance.
-
Loading States: Handle loading states to keep users informed during data fetching.
-
Error Handling: Gracefully handle errors during data retrieval.
- Customize the appearance and behavior of the clipboard according to your requirements:
PaginationCubit:
class PaginationCubit extends Cubit<List<dynamic>> {
PaginationCubit() : super([]);
int _page = 1;
bool _isFetching = false;
Future<void> fetchItems() async {
if (_isFetching) return;
_isFetching = true;
try {
final response = await Dio().get(
'https://jsonplaceholder.typicode.com/posts',
queryParameters: {'_page': _page, '_limit': 10});
final List<dynamic> items = response.data;
emit(List.from(state)..addAll(items));
_page++;
debugPrint('Page: $_page');
} catch (e) {
debugPrint('Error: $e');
} finally {
debugPrint('Total Fetched Items Num: ${state.length}');
_isFetching = false;
}
}
}
Easy.Pagination.Cubit.mp4
flutter_bloc: ^8.0.0
dio: ^4.0.0
- Contributions are welcome π
- If you find any issues or have suggestions for improvements, feel free to open an issue or submit a pull request.
- This package is distributed under the MIT License. Feel free to use and modify it according to your project requirements.
- If you find this tutorial useful or learned something from this code, consider show some β€οΈ by starring this repo.