Skip to content

Commit

Permalink
* Fixed a bug where fetchData was called twice if PaginationItemsStat…
Browse files Browse the repository at this point in the history
…eHandler was used as parent in release mode (optimization).

* Updated example app
* Updated version
  • Loading branch information
rithik-dev committed Mar 29, 2022
1 parent 98f40c6 commit 5181f67
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 16 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
## [1.0.6] - 29/03/2022

* Fixed a bug where fetchData was called twice if PaginationItemsStateHandler was used as parent in release mode (optimization).
* Updated example app

## [1.0.5] - 29/03/2022

* Added access/update to list elements by using [] syntax on PaginatedItemsResponse directly.
Expand Down
12 changes: 6 additions & 6 deletions example/lib/screens/home_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@ class HomeScreen extends StatelessWidget {

@override
Widget build(BuildContext context) {
return const PostsListWithController();
// return const PostsListWithoutController();
return const PostsListWithStateHandledExternally();
// return const PostsListWithStateHandledInternally();
}
}

//******************************************************************
// WITH CONTROLLER
//******************************************************************

class PostsListWithController extends StatelessWidget {
const PostsListWithController({
class PostsListWithStateHandledExternally extends StatelessWidget {
const PostsListWithStateHandledExternally({
Key? key,
}) : super(key: key);

Expand Down Expand Up @@ -59,8 +59,8 @@ class PostsListWithController extends StatelessWidget {
// WITHOUT CONTROLLER
//******************************************************************

class PostsListWithoutController extends StatelessWidget {
const PostsListWithoutController({
class PostsListWithStateHandledInternally extends StatelessWidget {
const PostsListWithStateHandledInternally({
Key? key,
}) : super(key: key);

Expand Down
12 changes: 3 additions & 9 deletions lib/src/paginated_items_builder.dart
Original file line number Diff line number Diff line change
Expand Up @@ -272,15 +272,9 @@ class _PaginatedItemsBuilderState<T> extends State<PaginatedItemsBuilder<T>> {
? _config?.mockItemGetter<T>()
: _config?.mockItemGetter(widget.mockItemKey);

late bool hasItemsStateHandlerAsParent;
context.visitAncestorElements((element) {
hasItemsStateHandlerAsParent =
element.toStringShort().contains('PaginationItemsStateHandler');

// stop visiting any more ancestors if already found i.e. return false.
return !hasItemsStateHandlerAsParent;
});
if (!hasItemsStateHandlerAsParent) _fetchData();
final itemsStateHandlerAsParent =
context.findAncestorWidgetOfExactType<PaginationItemsStateHandler<T>>();
if (itemsStateHandlerAsParent == null) _fetchData();

PaginatedItemsBuilder.config ??=
PaginatedItemsBuilderConfig.defaultConfig();
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: paginated_items_builder
description: Easier to display items in a list/grid view from your controllers directly or handling state internally with support for pagination.
version: 1.0.5
version: 1.0.6
homepage: https://github.com/rithik-dev/paginated_items_builder

environment:
Expand Down

0 comments on commit 5181f67

Please sign in to comment.