From a4531b6d111954940bc7fdefc8ed2b0cdeadee74 Mon Sep 17 00:00:00 2001 From: Arseny Savchenko Date: Tue, 26 Nov 2024 21:15:44 +0300 Subject: [PATCH 1/3] fetch index fix --- .gitignore | 2 +- lib/src/widget/bidirectional_paging_list_view.dart | 4 ++-- lib/src/widget/paging_sliver_list.dart | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 96486fd..0a7abe4 100644 --- a/.gitignore +++ b/.gitignore @@ -23,7 +23,7 @@ migrate_working_dir/ # Flutter/Dart/Pub related # Libraries should not include pubspec.lock, per https://dart.dev/guides/libraries/private-files#pubspeclock. -/pubspec.lock +*.lock **/doc/api/ .dart_tool/ .packages diff --git a/lib/src/widget/bidirectional_paging_list_view.dart b/lib/src/widget/bidirectional_paging_list_view.dart index ac5d645..bc14c6c 100644 --- a/lib/src/widget/bidirectional_paging_list_view.dart +++ b/lib/src/widget/bidirectional_paging_list_view.dart @@ -474,9 +474,9 @@ class _BidirectionalPagingListViewState // Check if the index corresponds to near the top or bottom based on the // 'reverse' flag. final nearTop = - reverse ? index == itemCount - fetchIndex : index == fetchIndex; + reverse ? index >= itemCount - fetchIndex : index <= fetchIndex; final nearBottom = - reverse ? index == fetchIndex : index == itemCount - fetchIndex; + reverse ? index <= fetchIndex : index >= itemCount - fetchIndex; // Generate prepend notification. if (nearTop) onBuildingPrependLoadTriggerItem?.call(); diff --git a/lib/src/widget/paging_sliver_list.dart b/lib/src/widget/paging_sliver_list.dart index 95830a2..b85db16 100644 --- a/lib/src/widget/paging_sliver_list.dart +++ b/lib/src/widget/paging_sliver_list.dart @@ -271,12 +271,12 @@ class _PagingSliverListState if (prefetchIndex == null) return; // Generate prepend notification. - if (index == prefetchIndex) { + if (index <= prefetchIndex) { onBuildingPrependLoadTriggerItem?.call(); } // Generate append notification. - if (index == itemCount - prefetchIndex) { + if (index >= itemCount - prefetchIndex) { onBuildingAppendLoadTriggerItem?.call(); } } From 9e75b787560ca3cbe452e8953787b1802d89f3f6 Mon Sep 17 00:00:00 2001 From: Arseny Savchenko Date: Wed, 27 Nov 2024 16:37:47 +0300 Subject: [PATCH 2/3] append & prepend multiple loading fix --- lib/src/page_fetcher.dart | 14 ++++++++++---- lib/src/widget/bidirectional_paging_list_view.dart | 8 ++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/lib/src/page_fetcher.dart b/lib/src/page_fetcher.dart index 60b9a0e..674dc01 100644 --- a/lib/src/page_fetcher.dart +++ b/lib/src/page_fetcher.dart @@ -136,10 +136,16 @@ class PageFetcher extends ValueNotifier> { log.fine('$loadType cancelled'); }, () async { - assert( - loadType != LoadType.refresh, - 'Use doInitialLoad for LoadType == refresh', - ); + switch (loadType) { + case LoadType.append: + if (value.appendLoadState == const LoadState.loading()) return; + + case LoadType.prepend: + if (value.prependLoadState == const LoadState.loading()) return; + + case LoadType.refresh: + throw ArgumentError('Use doInitialLoad for LoadType == refresh'); + } final loadKey = _nextLoadKeyOrNull(loadType); if (loadKey == null) return; diff --git a/lib/src/widget/bidirectional_paging_list_view.dart b/lib/src/widget/bidirectional_paging_list_view.dart index bc14c6c..6252a96 100644 --- a/lib/src/widget/bidirectional_paging_list_view.dart +++ b/lib/src/widget/bidirectional_paging_list_view.dart @@ -473,10 +473,10 @@ class _BidirectionalPagingListViewState // Check if the index corresponds to near the top or bottom based on the // 'reverse' flag. - final nearTop = - reverse ? index >= itemCount - fetchIndex : index <= fetchIndex; - final nearBottom = - reverse ? index <= fetchIndex : index >= itemCount - fetchIndex; + final nearUp = index <= fetchIndex; + final nearDown = index >= itemCount - fetchIndex; + final nearTop = reverse ? nearDown : nearUp; + final nearBottom = reverse ? nearUp : nearDown; // Generate prepend notification. if (nearTop) onBuildingPrependLoadTriggerItem?.call(); From f8b91a97325c9c1ce508be982bd3518e6a27813b Mon Sep 17 00:00:00 2001 From: Arseny Savchenko Date: Wed, 27 Nov 2024 16:47:51 +0300 Subject: [PATCH 3/3] append & prepend multiple loading fix --- lib/src/page_fetcher.dart | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/src/page_fetcher.dart b/lib/src/page_fetcher.dart index 674dc01..7b908ae 100644 --- a/lib/src/page_fetcher.dart +++ b/lib/src/page_fetcher.dart @@ -136,6 +136,7 @@ class PageFetcher extends ValueNotifier> { log.fine('$loadType cancelled'); }, () async { + // Ignore function call if pager is already loading switch (loadType) { case LoadType.append: if (value.appendLoadState == const LoadState.loading()) return;