Skip to content

Commit

Permalink
Merge pull request #244 from getBoolean/feature/pagination
Browse files Browse the repository at this point in the history
Add Riverpod Pagination Code
  • Loading branch information
getBoolean committed Apr 13, 2024
2 parents 32f55b4 + b421600 commit c9429ff
Show file tree
Hide file tree
Showing 26 changed files with 625 additions and 71 deletions.
File renamed without changes.
File renamed without changes.
6 changes: 0 additions & 6 deletions lib/src/features/pagination/paginated_response.dart

This file was deleted.

65 changes: 0 additions & 65 deletions lib/src/features/pagination/paginated_view.dart

This file was deleted.

29 changes: 29 additions & 0 deletions packages/pub/pagination/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# Miscellaneous
*.class
*.log
*.pyc
*.swp
.DS_Store
.atom/
.buildlog/
.history
.svn/
migrate_working_dir/

# IntelliJ related
*.iml
*.ipr
*.iws
.idea/

# The .vscode folder contains launch configuration and tasks you configure in
# VS Code which you may wish to be included in version control, so this line
# is commented out by default.
#.vscode/

# Flutter/Dart/Pub related
# Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock.
/pubspec.lock
**/doc/api/
.dart_tool/
build/
10 changes: 10 additions & 0 deletions packages/pub/pagination/.metadata
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# This file tracks properties of this Flutter project.
# Used by Flutter tool to assess capabilities and perform upgrades etc.
#
# This file should be version controlled and should not be manually edited.

version:
revision: "300451adae589accbece3490f4396f10bdf15e6e"
channel: "stable"

project_type: package
3 changes: 3 additions & 0 deletions packages/pub/pagination/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.0.1

* TODO: Describe initial release.
1 change: 1 addition & 0 deletions packages/pub/pagination/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
TODO: Add your license here.
66 changes: 66 additions & 0 deletions packages/pub/pagination/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/guides/libraries/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-library-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/developing-packages).
-->

A simple way to implement paginated results using riverpod providers

## Features

### Paginated View

A `StatelessWidget` that can be used to display a paginated list of items.

```dart
PaginatedView(
itemsProviderBuilder: (int page) => ref.watch(itemsProviderBuilder(
page: page,
)),
invalidateItemsProvider: () => ref.invalidate(itemsProviderBuilder),
invalidateItemPageProvider: (int page) =>
ref.invalidate(itemsProviderBuilder(
page: page,
)),
refreshItemPageProvider: (int page) async =>
await ref.watch(itemsProviderBuilder(
page: page,
)).future,
itemBuilder: (BuildContext context, T item, int indexInPage) => ...,
loadingItemBuilder: (BuildContext context, int page, int indexInPage) => ...,
errorItemBuilder: (BuildContext context, int page, int indexInPage, Object error, StackTrace stack) => ...,
shrinkWrap: true,
transitionDuration: const Duration(milliseconds: 650),
transitionCurve: Curves.easeInOut,
reverseTransitionCurve: null,
restorationId: null,
)
```

### Paginated Result

Implement a `PaginatedResult` for your API response. This result can then be used
anywhere a `PaginatedResult` is expected, such as with `PaginatedView`.

### Keep Alive Duration

Keeps an `autoDispose Provider` alive for a given `Duration` even if
the provider is no longer used.

```dart
keepAliveDuration<T>(
AutoDisposeRef<T> ref, [
Duration duration = const Duration(seconds: 30),
])
```

## Resources

- [Andrea's Pagination article](https://codewithandrea.com/articles/flutter-riverpod-pagination/)
4 changes: 4 additions & 0 deletions packages/pub/pagination/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
include: package:flutter_lints/flutter.yaml

# Additional information about this file can be found at
# https://dart.dev/guides/language/analysis-options
4 changes: 4 additions & 0 deletions packages/pub/pagination/lib/pagination.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
library pagination;

export 'package:pagination_dart/pagination_dart.dart';
export 'src/paginated_view.dart';
Loading

0 comments on commit c9429ff

Please sign in to comment.