我想知道在列表视图中向上或向下滚动时滚动的方向。但我找不到解决办法。
我尝试使用ScrollController侦听滚动方向,以处理上下滚动不同的工作。但是没有办法用ScrollController来听。 有没有人要解决这个问题?
答案 0 :(得分:0)
您可以使用NotificationListener<ScrollNotification>
。您需要将滚动视图包装在该小部件中,然后听UserScrollNotification
s:
NotificationListener<ScrollNotification>(
onNotification: (ScrollNotification notification) {
if (notification is UserScrollNotification) {
if (notification.direction == ScrollDirection.forward) {
// Handle scroll down.
} else if (notification.direction == ScrollDirection.reverse) {
// Handle scroll up.
}
}
// Returning null (or false) to
// "allow the notification to continue to be dispatched to further ancestors".
return null;
},
child: ListView(..), // Or whatever scroll view you use.
)