3

My widget renders a list of photos and installs a ScrollController to detect when the user scrolls to the bottom so new photos can be loaded. On some devices however the initial loaded photos don't cover the whole screen. In this case I want to load more photos until the whole screen is covered. How can I achieve that?

scrollController.addListener(() async {
  final pos = scrollController.position;
  final triggerFetchMoreSize = 0.9 * pos.maxScrollExtent;
  if (pos.pixels > triggerFetchMoreSize) {
       // scrolling to bottom detected
  }
}



SingleChildScrollView(controller: scrollController,
          physics: const AlwaysScrollableScrollPhysics(),
          child: PhotoList());
raaaay
  • 496
  • 7
  • 14
MarcS82
  • 2,065
  • 7
  • 29
  • 46

2 Answers2

2

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
-1

You could use MediaQuery to do it. You could find the height of the device by using MediaQuery.of<context>.size.height or width of the Device Screen using MediaQuery.of<context>.size.width

Reference: https://api.flutter.dev/flutter/widgets/MediaQuery-class.html

Humble
  • 41
  • 2
  • 8
  • Ok but how can find out if my list of photos is larger as `MediaQuery.of.size.height`? And where can I do the comparation makeing sure that my photolist is already drawn? – MarcS82 May 14 '20 at 15:19