What is the equivalent of Android's RecyclerView.SCROLL_STATE_IDLE in Flutter

故事扮演 提交于 2019-12-22 17:06:45

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!