Skip to content

Commit 3e251ae

Browse files
Updated Paginable to version 1.1.0
Added pub badge to README.md Updated dependencies Removed example section from README.md Added README.md to example folder Added documentation comments
1 parent 1115632 commit 3e251ae

13 files changed

+81
-30
lines changed

README.md

+3-6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
[![pub package](https://img.shields.io/pub/v/paginable.svg)](https://pub.dev/packages/paginable)
2+
13
Paginable is a Flutter package which makes pagination easier.
24

35
<p>
@@ -13,7 +15,7 @@ Paginable is a Flutter package which makes pagination easier.
1315

1416
## Paginable Widgets
1517

16-
- `PaginableListViewBuilder` is paginable's version of [`ListView.builder`](https://api.flutter.dev/flutter/widgets/ListView-class.html)
18+
- `PaginableListViewBuilder` is paginable's version of [`ListView.builder`](https://api.flutter.dev/flutter/widgets/ListView/ListView.builder.html)
1719
- `PaginableCustomScrollView` is paginable's version of [`CustomScrollView`](https://api.flutter.dev/flutter/widgets/CustomScrollView-class.html)
1820
- `PaginableSliverChildBuilderDelegate` is paginable's version of [`SliverChildBuilderDelegate`](https://api.flutter.dev/flutter/widgets/SliverChildBuilderDelegate-class.html)
1921

@@ -157,11 +159,6 @@ You might miss that the parameter `loadMore` is in `PaginableCustomScrollView`,
157159
>
158160
> Paginable is not resposible for managing states, to know about different ways of managing states in Flutter, [https://flutter.dev/docs/development/data-and-backend/state-mgmt/options](https://flutter.dev/docs/development/data-and-backend/state-mgmt/options)
159161
160-
## Examples
161-
162-
- [Using `PaginableListViewBuilder`](https://github.com/chinkysight/paginable/tree/main/example/paginablelistviewbuilder_example)
163-
- [Using `PaginableCustomScrollView` with `PaginableSliverChildBuilderDelegate`](https://github.com/chinkysight/paginable/tree/main/example/paginablesliverchildbuilderdelegate_example)
164-
165162
## Contribution
166163

167164
If you would like to contribute to the package (e.g. by improving the documentation, solving a bug or adding a cool new feature), you are welcomed and very much appreciated to send us your pull request and if you find something wrong with the package, please feel free to open an [issue](https://github.com/chinkysight/paginable/issues).

example/README.md

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
# Examples
2+
3+
## Using `PaginableListViewBuilder`
4+
5+
This example helps to understand the usage of `PaginableListViewBuilder`.
6+
7+
[Jump To Source](https://github.com/chinkysight/paginable/tree/main/example/paginablelistviewbuilder_example)
8+
9+
## Using `PaginableCustomScrollView` with `PaginableSliverChildBuilderDelegate`
10+
11+
This example helps to understand how we can use `PaginableCustomScrollView` with `PaginableSliverChildBuilderDelegate` to perform pagination.
12+
13+
[Jump To Source](https://github.com/chinkysight/paginable/tree/main/example/paginablesliverchildbuilderdelegate_example)

example/paginablelistviewbuilder_example/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ environment:
1111
dependencies:
1212
flutter:
1313
sdk: flutter
14-
paginable: ^1.0.0
14+
paginable: ^1.1.0
1515

16-
cupertino_icons: ^1.0.2
16+
cupertino_icons: ^1.0.3
1717

1818
dev_dependencies:
1919
flutter_test:
2020
sdk: flutter
2121

22-
flutter_lints: ^1.0.0
22+
flutter_lints: ^1.0.4
2323

2424
flutter:
2525
uses-material-design: true

example/paginablesliverchildbuilderdelegate_example/lib/utils.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,4 @@ Future<void> fetchFiveMore() async {
88
for (int i = 0; i < 5; i++) {
99
numbers.add(numbers.last + 1);
1010
}
11-
}
11+
}

example/paginablesliverchildbuilderdelegate_example/pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,15 @@ environment:
1111
dependencies:
1212
flutter:
1313
sdk: flutter
14-
paginable: ^1.0.0
14+
paginable: ^1.1.0
1515

16-
cupertino_icons: ^1.0.2
16+
cupertino_icons: ^1.0.3
1717

1818
dev_dependencies:
1919
flutter_test:
2020
sdk: flutter
2121

22-
flutter_lints: ^1.0.0
22+
flutter_lints: ^1.0.4
2323

2424
flutter:
2525
uses-material-design: true

example/paginablesliverchildbuilderdelegate_example/test/utils_test.dart

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ void main() {
1313
expect(numbers.length, 25);
1414
},
1515
);
16-
}
16+
}

lib/src/paginable_custom_scroll_view.dart

+7
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ import 'package:provider/provider.dart';
44

55
import 'utils/last_item.dart';
66

7+
/// It is the paginable's version of [CustomScrollView](https://api.flutter.dev/flutter/widgets/CustomScrollView-class.html) and it is used along with [PaginableSliverChildBuilderDelegate](https://pub.dev/packages/paginable#using-paginablecustomscrollview-with-paginablesliverchildbuilderdelegate) to perform pagination.
78
class PaginableCustomScrollView extends StatefulWidget {
9+
/// It takes an async function which will be executed when the scroll is almost at the end.
810
final Future<void> Function() loadMore;
911

1012
// ignore: annotate_overrides, overridden_fields
@@ -19,13 +21,18 @@ class PaginableCustomScrollView extends StatefulWidget {
1921
final Key? center;
2022
final double anchor;
2123
final double? cacheExtent;
24+
25+
/// The slivers to place inside the viewport.
2226
final List<Widget> slivers;
2327
final int? semanticChildCount;
2428
final DragStartBehavior dragStartBehavior;
2529
final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior;
2630
final String? restorationId;
2731
final Clip clipBehavior;
2832

33+
/// Creates a [ScrollView] that creates custom scroll effects using slivers.
34+
///
35+
/// See the [ScrollView] constructor for more details on these arguments.
2936
const PaginableCustomScrollView(
3037
{this.key,
3138
this.scrollDirection = Axis.vertical,

lib/src/paginable_listview_builder.dart

+17-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,26 @@ import 'package:flutter/material.dart';
33
import 'utils/last_item.dart';
44
import 'utils/scroll_position.dart';
55

6+
/// It is paginable's version of [ListView.builder](https://api.flutter.dev/flutter/widgets/ListView/ListView.builder.html)
67
class PaginableListViewBuilder extends StatefulWidget {
78
final double? itemExtent;
9+
10+
/// It takes a function which contains two parameters, one being of type `Exception` and other being a
11+
/// `Function()`, returning a widget which will be displayed at the bottom of the scrollview when an
12+
/// exception occurs in the async function which we passed to the `loadMore` parameter.
13+
///
14+
/// The parameter with type `Exception` will contain the exception which occured while executing the
15+
/// function passed to the parameter `loadMore` if exception occured, and the parameter with type `Function()`
16+
/// will contain the same function which we passed to the `loadMore` parameter.
817
final Widget Function(Exception exception, void Function() tryAgain)
918
errorIndicatorWidget;
19+
20+
/// It takes a widget which will be displayed at the bottom of the scrollview to indicate the user that
21+
/// the async function we passed to the `loadMore` parameter is being executed.
1022
final Widget progressIndicatorWidget;
1123
final Widget Function(BuildContext context, int index) itemBuilder;
24+
25+
/// It takes an async function which will be executed when the scroll is almost at the end.
1226
final Future<void> Function() loadMore;
1327
final ScrollController? controller;
1428
final Axis scrollDirection;
@@ -27,6 +41,8 @@ class PaginableListViewBuilder extends StatefulWidget {
2741
final ScrollViewKeyboardDismissBehavior keyboardDismissBehavior;
2842
final String? restorationId;
2943
final Clip clipBehavior;
44+
45+
/// Creates a scrollable, linear array of widgets that are created on demand.
3046
const PaginableListViewBuilder(
3147
{Key? key,
3248
this.scrollDirection = Axis.vertical,
@@ -112,8 +128,7 @@ class _PaginableListViewBuilderState extends State<PaginableListViewBuilder> {
112128
if (value == LastItem.emptyContainer) {
113129
return Container();
114130
} else if (value == LastItem.errorIndicator) {
115-
return widget.errorIndicatorWidget(
116-
exception, tryAgain);
131+
return widget.errorIndicatorWidget(exception, tryAgain);
117132
}
118133
return widget.progressIndicatorWidget;
119134
});

lib/src/paginable_sliver_child_builder_delegate.dart

+19
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,25 @@ import 'package:flutter/material.dart';
33
import 'package:paginable/src/utils/last_item.dart';
44
import 'package:provider/provider.dart';
55

6+
/// It is the is paginable's version of [SliverChildBuilderDelegate](https://api.flutter.dev/flutter/widgets/SliverChildBuilderDelegate-class.html) and it is used along with [PaginableCustomScrollView](https://pub.dev/packages/paginable#using-paginablecustomscrollview-with-paginablesliverchildbuilderdelegate) to perform pagination.
67
class PaginableSliverChildBuilderDelegate {
78
static int _kDefaultSemanticIndexCallback(Widget _, int localIndex) =>
89
localIndex;
910

1011
final NullableIndexedWidgetBuilder builder;
12+
13+
/// It takes a function which contains two parameters, one being of type `Exception` and other being a
14+
/// `Function()`, returning a widget which will be displayed at the bottom of the scrollview when an
15+
/// exception occurs in the async function which we passed to the `loadMore` parameter.
16+
///
17+
/// The parameter with type `Exception` will contain the exception which occured while executing the
18+
/// function passed to the parameter `loadMore` if exception occured, and the parameter with type `Function()`
19+
/// will contain the same function which we passed to the `loadMore` parameter.
1120
final Widget Function(Exception exception, void Function() tryAgain)
1221
errorIndicatorWidget;
22+
23+
/// It takes a widget which will be displayed at the bottom of the scrollview to indicate the user that
24+
/// the async function we passed to the `loadMore` parameter is being executed.
1325
final Widget progressIndicatorWidget;
1426
final int? Function(Key)? findChildIndexCallback;
1527
final int? childCount;
@@ -30,6 +42,13 @@ class PaginableSliverChildBuilderDelegate {
3042
this.semanticIndexCallback = _kDefaultSemanticIndexCallback,
3143
this.semanticIndexOffset = 0});
3244

45+
/// Creates a delegate that supplies children for slivers using the given
46+
/// builder callback.
47+
///
48+
/// If the order in which [builder] returns children ever changes, consider
49+
/// providing a [findChildIndexCallback]. This allows the delegate to find the
50+
/// new index for a child that was previously located at a different index to
51+
/// attach the existing state to the [Widget] at its new location.
3352
SliverChildBuilderDelegate build() =>
3453
SliverChildBuilderDelegate((BuildContext context, int index) {
3554
if (index == childCount) {

lib/src/utils/last_item.dart

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1 @@
1-
enum LastItem {
2-
progressIndicator,
3-
errorIndicator,
4-
emptyContainer
5-
}
1+
enum LastItem { progressIndicator, errorIndicator, emptyContainer }

pubspec.yaml

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: paginable
2-
description: A Flutter package which makes pagination easier.
3-
version: 1.0.0
2+
description: Paginable is a Flutter package which makes pagination easier by providing more functionality on top of native widgets.
3+
version: 1.1.0
44
homepage: https://github.com/chinkysight/paginable
55

66
environment:
@@ -10,7 +10,7 @@ environment:
1010
dependencies:
1111
flutter:
1212
sdk: flutter
13-
provider: ^6.0.0
13+
provider: ^6.0.1
1414

1515
dev_dependencies:
1616
flutter_lints: ^1.0.4

test/paginable_listview_builder_test.dart

+6-4
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ void main() {
5757

5858
final exceptionFinder = find.text(exception.toString());
5959

60-
bool isRedContainer(Widget widget)=>
60+
bool isRedContainer(Widget widget) =>
6161
widget is Container && widget.color == Colors.redAccent;
6262

6363
expect(exceptionFinder, findsOneWidget);
@@ -79,8 +79,9 @@ void main() {
7979
scrollToTheEndOfScrollView(scrollController);
8080
await tester.pump();
8181

82-
bool isEmptyContainer(Widget widget) => widget is Container && widget.child == null;
83-
82+
bool isEmptyContainer(Widget widget) =>
83+
widget is Container && widget.child == null;
84+
8485
expect(find.byWidgetPredicate(isEmptyContainer), findsOneWidget);
8586
});
8687

@@ -98,7 +99,8 @@ void main() {
9899
scrollToTheEndOfScrollView(scrollController);
99100
await tester.pump(const Duration(seconds: 3));
100101

101-
bool isEmptyContainer(Widget widget) => widget is Container && widget.child == null;
102+
bool isEmptyContainer(Widget widget) =>
103+
widget is Container && widget.child == null;
102104

103105
expect(find.byWidgetPredicate(isEmptyContainer), findsOneWidget);
104106
});

test/paginable_sliver_child_builder_delegate_test.dart

+4-2
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,8 @@ void main() {
7878
scrollToTheEndOfScrollView(scrollController);
7979
await tester.pump();
8080

81-
bool isEmptyContainer(Widget widget) => widget is Container && widget.child == null;
81+
bool isEmptyContainer(Widget widget) =>
82+
widget is Container && widget.child == null;
8283

8384
expect(find.byWidgetPredicate(isEmptyContainer), findsOneWidget);
8485
});
@@ -97,7 +98,8 @@ void main() {
9798
scrollToTheEndOfScrollView(scrollController);
9899
await tester.pump(const Duration(seconds: 3));
99100

100-
bool isEmptyContainer(Widget widget) => widget is Container && widget.child == null;
101+
bool isEmptyContainer(Widget widget) =>
102+
widget is Container && widget.child == null;
101103

102104
expect(find.byWidgetPredicate(isEmptyContainer), findsOneWidget);
103105
});

0 commit comments

Comments
 (0)