CustomScrollView used in home page layout If you want to pull up and load more, you must define a ScrollController and pass it to CustomScrollView.
My code
ScrollController _scrollController = new ScrollController();
@override
void initState() {
super.initState();
_scrollController.addListener(() {
if (_scrollController.position.pixels >=
_scrollController.position.maxScrollExtent) {
_loadMoreData();
}
});
}
@override
void dispose() {
super.dispose();
_scrollController.dispose();
}
new CustomScrollView(
controller: _scrollController,
slivers: <Widget>[....],
)
However, if this is done, when there is a lot of data loaded, tap the status bar at the top will not scroll to the top! If you remove the controller in CustomScrollView, or change to PrimaryScrollController.of(context)
new CustomScrollView(
controller: PrimaryScrollController.of(context),
)
this is OK! why ???
Because Flutter engine tries to imitate the OS behaviour as closely as possible. This tap gesture is known as "return-to-top" on iOS and doesn't exist on Android at all. Furthermore, to stay as close to the iOS app behaviour as possible, this gesture only triggers the scrolling animation for PrimaryScrollController
classes.
As a reference, in iOS native app development the scroll-to-top gesture has no effect if there is more than one scroll view on-screen that has scrollsToTop set to true (source).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With