-1

I have a GridView that loads lazily at the end of the scroll controller, however I want to load the data when I reach halfway through the scroll controller. If I try to do an if statement that checks if the scroll has reached 50% of the controller it will never become equal, however, if I do a greater than equal to 50% it calls the function multiple times ending in duplicates of data. How can I avoid this duplication or is there a better way to do this.

Zahid Ahmed
  • 9
  • 1
  • 4
  • Please read about this: https://api.flutter.dev/flutter/widgets/ScrollController-class.html. You can track your scroll using this – Alok May 10 '20 at 13:58
  • I guess this is something you are trying to do.. https://stackoverflow.com/a/49509349/13460232 – srikanth7785 May 11 '20 at 11:51

2 Answers2

0

A simple way to do it is just use your current code and an additional boolean 'wasCalled' which you set to true in the function. But: I'm confident there's better solutions.

I haven't really worked with GridViews, but as far as I understand it builds its children lazily. Have you tried inserting a custom widget in the middle of the children's list?

E.g. in your build function you could:

@override
Widget build(BuildContext _) {
  callCustomFunction();
  return Container();
}
rgisi
  • 858
  • 6
  • 21
0

You can use the "extentAfter" property to know how much more space is left till the end..

I guess this is something you are trying to do..

https://stackoverflow.com/a/49509349/13460232

srikanth7785
  • 1,382
  • 1
  • 7
  • 22