Android gives scroll states like RecyclerView.SCROLL_STATE_IDLE which tells when user stops the scroll. I'm not able to find any alternative in flutter for Pageview or ListView ScrollListener.
My Problem
I need to detect scroll up/down in PageView to perform some operation based on that. Flutter gives the direction (_myPageViewController.position.userScrollDirection) but it gives a continuous callback. I need to detect it only when the user stops scrolling.
Another scenario
I need to do auto-play videos in a listView. So I need to detect when the user stops scrolling and then get the position and play that.
In android I would have done this with the help RecyclerView.SCROLL_STATE_IDLE state in RecyclerView's scrollListener. Need something similar in flutter.
According to @pskink and @doc NotificationListener<ScrollNotification> gives the callback of scroll start, scroll end.
NotificationListener<ScrollNotification>(
onNotification: (scrollNotification) {
if (scrollNotification is ScrollEndNotification) {
print("Scroll End"); //Scroll end callback
}
return false;
},
child: ListView.builder(
//...
),
)
This also works with other scrollable widgets like PageView.
来源:https://stackoverflow.com/questions/57232156/what-is-the-equivalent-of-androids-recyclerview-scroll-state-idle-in-flutter