如何检测用户是否开始垂直滚动 Listview.builder?

How to detect if the user started scrolling the Listview.builder vertically?

我试图在用户开始滚动时隐藏一个容器,这样它会提供更多 space 和列表视图的可见性。我尝试将 Gesturedetector 作为 Listview.builer 的父级并使用它的 "onVerticalDragStart" 但没有运气。我是颤振的初学者,希望你能帮助我。谢谢!

您可以使用 ScrollController, but @Sp4Rx proposed a better solution: NotificationListener<ScrollNotification>

您只需将 ListView.builder 包装在具有通用类型 ScrollNotificationNotificationListener 中,以处理通过滚动 ListView:[=22= 发送的 ScrollNotifications ]

NotificationListener<ScrollNotification>(
  onNotification: (ScrollNotification notification) {
    if (notification is ScrollStartNotification) {
      // Handle your desired action on scroll start here.
    }

    // Returning null (or false) to
    // "allow the notification to continue to be dispatched to further ancestors".
    return null;
  },
  child: ListView.builder(...),
)

您可以查看 ScrollStartNotification here 的文档。