Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Try to fix double fetch #366

Closed

Conversation

EArminjon
Copy link

@EArminjon EArminjon commented Mar 14, 2025

We have difficulty to upgrade to infinite_scroll_pagination: 5.0.0 due to this issue : #365

@@ -260,7 +261,7 @@ class _PagedLayoutBuilderState<PageKeyType, ItemType>
// This behaviour is okay because we make sure not to excessively request pages.
final hasPassedTrigger = index >= triggerIndex;

if (_hasNextPage && hasPassedTrigger) {
if (_hasNextPage && hasPassedTrigger && !_state.isLoading) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one i didn't understand why it is needed, why this method is called twice is a mystery.

@@ -162,7 +162,7 @@ class _PagedLayoutBuilderState<PageKeyType, ItemType>
@override
void initState() {
super.initState();
if (_state.status == PagingStatus.loadingFirstPage) {
if (_state.status == PagingStatus.loadingFirstPage && !_state.isLoading) {
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This add a little more flexibility : if initial state is already loading, why start a new one.

@@ -172,7 +172,8 @@ class _PagedLayoutBuilderState<PageKeyType, ItemType>
covariant PagedLayoutBuilder<PageKeyType, ItemType> oldWidget) {
super.didUpdateWidget(oldWidget);
if (oldWidget.state != widget.state) {
if (_state.status == PagingStatus.loadingFirstPage) {
if (_state.status == PagingStatus.loadingFirstPage
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I printed oldWidget.state and widget.state

I/flutter (15329): PagingStateBase<int, String>(pages: null, keys: null, error: null, hasNextPage: true, isLoading: false)
I/flutter (15329): PagingStateBase<int, String>(pages: null, keys: null, error: null, hasNextPage: true, isLoading: true)

As you can see, _fetchNextPage() will call again _fetchNextPage() when isLoading is true.

@clragon
Copy link
Collaborator

clragon commented Mar 14, 2025

The fetch function must deduplicate fetch calls for the reason mentioned in the issue.
Previously, isLoading did not exist and the Paged Layouts relied on computed state found in the extension methods to understand when to request a new page. This is still happening. We might replace this mechanism at some point, but for now I would like to keep it, as I have not fully thought about the implications. Thank you for your PR!

@clragon clragon closed this Mar 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants