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());
2
  • do you have all of those photos in a listview..? Commented May 14, 2020 at 15:09
  • all photos are in a gridview Commented May 14, 2020 at 15:17

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

-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

1 Comment

Ok but how can find out if my list of photos is larger as MediaQuery.of<context>.size.height? And where can I do the comparation makeing sure that my photolist is already drawn?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.