How can I realize items lazy loading for endless listview? I want to load more items by network when user scroll to the end of listview.
相关问题
- Flutter : Prepare list data from http request
- How to schedule an alarm on specific time in Flutt
- MappedListIterable is not a SubType
- 'firebase_messaging/FirebaseMessagingPlugin.h&
- What is the difference between generics and dynami
相关文章
- Observatory server failed to start - Fails to crea
- Flutter error retrieving device properties for ro.
- Adding Shadows at the bottom of a container in flu
- Flutter. Check if a file exists before loading it
- Flutter - http.get fails on macos build target: Co
- Receive share file intents with Flutter
- Do stateless widgets dispose on their own?
- How to clean your build with Flutter RP2 in Androi
You can listen to a
ScrollController
.ScrollController
has a few useful informations, such as the scrolloffset and a list ofScrollPosition
.In your case the interesting part is in
controller.position
which is the currently visibleScrollPosition
. Which represents a segment of the scrollable.ScrollPosition
contains informations about it's position inside the scrollable. Such asextentBefore
andextentAfter
. Or it's size, withextentInside
.Considering this, you could trigger a server call based on
extentAfter
which represents the remaining scroll space available.Here's an basic example using what I said.
You can clearly see that when reaching the end of the scroll, it scrollbar expends due to having loaded more items.
Thanks for Rémi Rousselet's approach, but it does not solve all the problem. Especially when the ListView has scrolled to the bottom, it still calls the scrollListener a couple of times. The better approach is to combine Notification Listener with Remi's approach. Here is my solution: