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/page_fetcher.dart b/lib/src/page_fetcher.dart index 60b9a0e..7b908ae 100644 --- a/lib/src/page_fetcher.dart +++ b/lib/src/page_fetcher.dart @@ -136,10 +136,17 @@ class PageFetcher extends ValueNotifier> { log.fine('$loadType cancelled'); }, () async { - assert( - loadType != LoadType.refresh, - 'Use doInitialLoad for LoadType == refresh', - ); + // Ignore function call if pager is already loading + 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 ac5d645..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(); 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(); } }