相当于Flutter中的Android RecyclerView.SCROLL_STATE_IDLE [英] What is the equivalent of Android's RecyclerView.SCROLL_STATE_IDLE in Flutter
问题描述
Android提供类似于RecyclerView.SCROLL_STATE_IDLE
的滚动状态,该状态指示用户何时停止滚动.我无法在Pageview
或ListView
ScrollListener的颤振中找到任何替代.
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.
我需要检测PageView中的向上/向下滚动,以基于此执行一些操作. Flutter提供了方向(_myPageViewController.position.userScrollDirection
),但提供了连续的回调.我只需要在用户停止滚动时才能检测到它.
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.
我需要在listView中自动播放视频.因此,我需要检测用户何时停止滚动,然后获取位置并进行播放.
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.
在android中,我会使用RecyclerView's
scrollListener中的帮助RecyclerView.SCROLL_STATE_IDLE
状态来完成此操作.需要一些类似的东西.
In android I would have done this with the help RecyclerView.SCROLL_STATE_IDLE
state in RecyclerView's
scrollListener. Need something similar in flutter.
推荐答案
根据 @pskink 和@doc NotificationListener<ScrollNotification>
给出了滚动开始,滚动结束的回调.
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(
//...
),
)
这也可以与其他可滚动小部件(例如PageView
)一起使用.
This also works with other scrollable widgets like PageView
.
这篇关于相当于Flutter中的Android RecyclerView.SCROLL_STATE_IDLE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!