From 684f3ff27563192c00c07ec294e73f6db20a3967 Mon Sep 17 00:00:00 2001 From: Timur Yusupov Date: Wed, 14 Aug 2024 17:32:40 +0400 Subject: [PATCH 1/5] fix empty state --- lib/src/loadable/loadable_list_view.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/src/loadable/loadable_list_view.dart b/lib/src/loadable/loadable_list_view.dart index b2e8261..8ff6798 100644 --- a/lib/src/loadable/loadable_list_view.dart +++ b/lib/src/loadable/loadable_list_view.dart @@ -201,7 +201,7 @@ class LoadableListViewModel { } if ((loadListRequestState.isSucceed || loadListRequestState.isRefreshing) && - itemCount == 0) { + itemCount == 1) { return PaginationState.empty; } From 0bc459d9fa996d5f06f0f0fabeead6cd44933cc2 Mon Sep 17 00:00:00 2001 From: Timur Yusupov Date: Wed, 14 Aug 2024 17:41:43 +0400 Subject: [PATCH 2/5] fix paginated list view --- lib/src/loadable/loadable_list_view.dart | 2 +- lib/src/loadable/loadable_paginated_list_view.dart | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/loadable/loadable_list_view.dart b/lib/src/loadable/loadable_list_view.dart index 8ff6798..b2e8261 100644 --- a/lib/src/loadable/loadable_list_view.dart +++ b/lib/src/loadable/loadable_list_view.dart @@ -201,7 +201,7 @@ class LoadableListViewModel { } if ((loadListRequestState.isSucceed || loadListRequestState.isRefreshing) && - itemCount == 1) { + itemCount == 0) { return PaginationState.empty; } diff --git a/lib/src/loadable/loadable_paginated_list_view.dart b/lib/src/loadable/loadable_paginated_list_view.dart index f72787c..f3bf805 100644 --- a/lib/src/loadable/loadable_paginated_list_view.dart +++ b/lib/src/loadable/loadable_paginated_list_view.dart @@ -116,6 +116,10 @@ class LoadablePaginatedListViewModel extends LoadableListViewModel { return PaginationState.loadingPage; } else if (loadPageRequestState.isSucceed) { return PaginationState.succeedLoadingPage; + } else if ((loadListRequestState.isSucceed || + loadListRequestState.isRefreshing) && + itemCount == 1) { + return PaginationState.empty; } return PaginationState.idle; From ed1952082baf0cc8b31ba691637030fa3bb92027 Mon Sep 17 00:00:00 2001 From: Timur Yusupov Date: Wed, 14 Aug 2024 18:06:15 +0400 Subject: [PATCH 3/5] add _actualItemsCount to paginated list view --- lib/src/loadable/loadable_paginated_list_view.dart | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/src/loadable/loadable_paginated_list_view.dart b/lib/src/loadable/loadable_paginated_list_view.dart index f3bf805..64dfa42 100644 --- a/lib/src/loadable/loadable_paginated_list_view.dart +++ b/lib/src/loadable/loadable_paginated_list_view.dart @@ -26,9 +26,11 @@ class LoadablePaginatedListState extends LoadableListViewState { LoadablePaginatedListViewModel get viewModel => widget.viewModel as LoadablePaginatedListViewModel; + int get _actualItemsCount => viewModel.itemCount + 1; + @override Widget buildListItem(int index) { - return index == viewModel.itemCount - 1 + return index == _actualItemsCount - 1 // ignore: avoid-returning-widgets ? buildLastItem(viewModel.getPaginationState()) : super.buildListItem(index); @@ -85,7 +87,7 @@ class LoadablePaginatedListViewModel extends LoadableListViewModel { required super.errorWidget, required super.emptyStateWidget, required super.loadListRequestState, - required int itemCount, + required super.itemCount, required this.loadPageRequestState, required this.errorPageWidget, required this.isAllItemsLoaded, @@ -96,7 +98,7 @@ class LoadablePaginatedListViewModel extends LoadableListViewModel { super.footer, this.loadPage, super.key, - }) : super(itemCount: itemCount + 1); + }); final VoidCallback? loadPage; final Widget errorPageWidget; @@ -116,10 +118,6 @@ class LoadablePaginatedListViewModel extends LoadableListViewModel { return PaginationState.loadingPage; } else if (loadPageRequestState.isSucceed) { return PaginationState.succeedLoadingPage; - } else if ((loadListRequestState.isSucceed || - loadListRequestState.isRefreshing) && - itemCount == 1) { - return PaginationState.empty; } return PaginationState.idle; From 657c9c3afd47be056495d2237959d9db187a4def Mon Sep 17 00:00:00 2001 From: Timur Yusupov Date: Wed, 14 Aug 2024 18:27:29 +0400 Subject: [PATCH 4/5] add getter to LoadableListViewState --- lib/src/loadable/loadable_list_view.dart | 4 +++- lib/src/loadable/loadable_paginated_list_view.dart | 5 +++-- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/src/loadable/loadable_list_view.dart b/lib/src/loadable/loadable_list_view.dart index b2e8261..5764d95 100644 --- a/lib/src/loadable/loadable_list_view.dart +++ b/lib/src/loadable/loadable_list_view.dart @@ -42,6 +42,8 @@ class LoadableListView extends StatefulWidget { class LoadableListViewState extends State { LoadableListViewModel get viewModel => widget.viewModel; + int get actualItemsCount => viewModel.itemCount; + @override void initState() { super.initState(); @@ -111,7 +113,7 @@ class LoadableListViewState extends State { sliver: SliverList( delegate: SliverChildBuilderDelegate( sliverDelegateBuilder, - childCount: _computeActualChildCount(viewModel.itemCount), + childCount: _computeActualChildCount(actualItemsCount), ), ), ), diff --git a/lib/src/loadable/loadable_paginated_list_view.dart b/lib/src/loadable/loadable_paginated_list_view.dart index 64dfa42..ee8f1f5 100644 --- a/lib/src/loadable/loadable_paginated_list_view.dart +++ b/lib/src/loadable/loadable_paginated_list_view.dart @@ -26,11 +26,12 @@ class LoadablePaginatedListState extends LoadableListViewState { LoadablePaginatedListViewModel get viewModel => widget.viewModel as LoadablePaginatedListViewModel; - int get _actualItemsCount => viewModel.itemCount + 1; + @override + int get actualItemsCount => viewModel.itemCount + 1; @override Widget buildListItem(int index) { - return index == _actualItemsCount - 1 + return index == actualItemsCount - 1 // ignore: avoid-returning-widgets ? buildLastItem(viewModel.getPaginationState()) : super.buildListItem(index); From 48ecbeab5ed517bb8ec8767778b79a9d1955a766 Mon Sep 17 00:00:00 2001 From: Timur Yusupov Date: Wed, 14 Aug 2024 18:36:11 +0400 Subject: [PATCH 5/5] update version and changelog --- CHANGELOG.md | 4 ++++ pubspec.yaml | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3362150..35b0735 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## [4.6.1] + +- Fix empty state. + ## [4.6.0] - Refactored LoadableList & PaginatedeLoadableList constructors signature diff --git a/pubspec.yaml b/pubspec.yaml index 7afd122..163d376 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: dash_kit_core description: The core component for DashKit that provides basic architecture components -version: 4.6.0 +version: 4.6.1 homepage: https://github.com/Dash-Kit/dash-kit-core environment: