Skip to content

Commit 5181f67

Browse files
committed
* Fixed a bug where fetchData was called twice if PaginationItemsStateHandler was used as parent in release mode (optimization).
* Updated example app * Updated version
1 parent 98f40c6 commit 5181f67

4 files changed

Lines changed: 15 additions & 16 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## [1.0.6] - 29/03/2022
2+
3+
* Fixed a bug where fetchData was called twice if PaginationItemsStateHandler was used as parent in release mode (optimization).
4+
* Updated example app
5+
16
## [1.0.5] - 29/03/2022
27

38
* Added access/update to list elements by using [] syntax on PaginatedItemsResponse directly.

example/lib/screens/home_screen.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,17 @@ class HomeScreen extends StatelessWidget {
1414

1515
@override
1616
Widget build(BuildContext context) {
17-
return const PostsListWithController();
18-
// return const PostsListWithoutController();
17+
return const PostsListWithStateHandledExternally();
18+
// return const PostsListWithStateHandledInternally();
1919
}
2020
}
2121

2222
//******************************************************************
2323
// WITH CONTROLLER
2424
//******************************************************************
2525

26-
class PostsListWithController extends StatelessWidget {
27-
const PostsListWithController({
26+
class PostsListWithStateHandledExternally extends StatelessWidget {
27+
const PostsListWithStateHandledExternally({
2828
Key? key,
2929
}) : super(key: key);
3030

@@ -59,8 +59,8 @@ class PostsListWithController extends StatelessWidget {
5959
// WITHOUT CONTROLLER
6060
//******************************************************************
6161

62-
class PostsListWithoutController extends StatelessWidget {
63-
const PostsListWithoutController({
62+
class PostsListWithStateHandledInternally extends StatelessWidget {
63+
const PostsListWithStateHandledInternally({
6464
Key? key,
6565
}) : super(key: key);
6666

lib/src/paginated_items_builder.dart

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -272,15 +272,9 @@ class _PaginatedItemsBuilderState<T> extends State<PaginatedItemsBuilder<T>> {
272272
? _config?.mockItemGetter<T>()
273273
: _config?.mockItemGetter(widget.mockItemKey);
274274

275-
late bool hasItemsStateHandlerAsParent;
276-
context.visitAncestorElements((element) {
277-
hasItemsStateHandlerAsParent =
278-
element.toStringShort().contains('PaginationItemsStateHandler');
279-
280-
// stop visiting any more ancestors if already found i.e. return false.
281-
return !hasItemsStateHandlerAsParent;
282-
});
283-
if (!hasItemsStateHandlerAsParent) _fetchData();
275+
final itemsStateHandlerAsParent =
276+
context.findAncestorWidgetOfExactType<PaginationItemsStateHandler<T>>();
277+
if (itemsStateHandlerAsParent == null) _fetchData();
284278

285279
PaginatedItemsBuilder.config ??=
286280
PaginatedItemsBuilderConfig.defaultConfig();

pubspec.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: paginated_items_builder
22
description: Easier to display items in a list/grid view from your controllers directly or handling state internally with support for pagination.
3-
version: 1.0.5
3+
version: 1.0.6
44
homepage: https://github.com/rithik-dev/paginated_items_builder
55

66
environment:

0 commit comments

Comments
 (0)