Network request before ListView reaches the end. Lazy loading

To add additional data to the ListView I use maxScrollExtent

  _controller.addListener(() {
    if (_controller.position.pixels == _controller.position.maxScrollExtent){
       //Get data request here
   });

But I wanted the user to not wait for the data to load, and load the data a little earlier, at 70% -80% of the list length. I tried such a solution but it does not work _controller.position.maxScrollExtent-200

Nothing happens, there is no error, the _controller.addListener is not executed.

Upvotes: 1

Views: 104

Answers (1)

chunhunghan
chunhunghan

Reputation: 54367

please change condition from == to >=
I have tested with your previous question
code snippet

_controller.addListener(() {
    if (_controller.position.pixels == _controller.position.maxScrollExtent - 200){
       //Get data request here
   });

to

_controller.addListener(() {
    if (_controller.position.pixels >= _controller.position.maxScrollExtent - 200){
       //Get data request here
   });

Upvotes: 1

Related Questions