skip to Main Content

Here’s my function:

  _onScroll() async {
if (_postScrollController.offset >=
        _postScrollController.position.maxScrollExtent - 1000 &&
    !_postScrollController.position.outOfRange) {

       *Function to get next set of data*

    }

The problem that I’m facing with this function is whenever you scroll too quickly, it will sometimes load and call the function multiple times.

If I remove the - 1000 from the function, it works well but leaves you stuck for a few seconds at the bottom of the page waiting for the next set of data to load before you can keep scrolling, it’s simply not very user friendly.

Is there any way of achieving infinite scroll in Flutter without using a dependency?

Thank you!

2

Answers


  1. Try this

    scrollController!.addListener(() async {
      if (scrollController!.position.maxScrollExtent ==
          scrollController!.position.pixels) {
       *Function to get next set of data*
      } 
    });
    
    Login or Signup to reply.
  2. If you wrap your master list in a riverpod provider, it doesn’t matter how quickly ref.invalidate is called… it’ll only ever rebuild once per frame, and then it has the cache of the new data.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search