EdsonBueno / infinite_scroll_pagination

Flutter package to help you lazily load and display pages of items as the user scrolls down your screen.
https://pub.dev/packages/infinite_scroll_pagination
MIT License
605 stars 201 forks source link

No items fetched after fetching less than invisibleItemsThreshold items #311

Open KrisBraun opened 5 months ago

KrisBraun commented 5 months ago

Hit this issue when using invisibleItemsThreshold = 20 with a fetcher that returns one item at a time.

This code assumes a fetch only needs to be triggered when crossing the threshold, while further fetches may be required after that one completes.

caiombueno commented 5 months ago

Hi @KrisBraun. A page is only requested when the trigger index item (newPageRequestTriggerIndex) is built/rebuilt. When the invisibleItemsThreshold value is too high, the trigger index item won't be at the end of the list. So, when you reach the end of the list, no more items will be fetched.

KrisBraun commented 5 months ago

Right. My use case is that I'd like to prefetch items early at an offset greater than the fetch page size (which is non-deterministic in my case).

If there's a way to detect when new items are added, this could be handled by generating another fetch if the total remaining items is still below the threshold.

clragon commented 4 months ago

You can listen to the pagecontroller, which will send a notification when new items are added. Is that an appropriate solution for your issue?

KrisBraun commented 4 months ago

I think for that to work, I'd need a way to determine the number of invisible items given the current position, so I could trigger additional fetches if there are fewer than the threshold remaining. As far as I can tell, none of that is accessible through the PagingController.

The cleanest solution from my perspective (external to the implementation) would be for the PagingController to fetch additional pages until it is above the threshold.

clragon commented 4 months ago

This seems reasonable on the first glance but I am unsure if it is desirable for the package to start making many requests like that.

I dont have time to specify this right now, but