scrollNotification.depth == 0
ListView里面如果包含Banner,这时候NotificationListener就会监听两个scroll的滚动事件(ListView的上下滚动和Banner的左右滚动),depth是给到我们选择性的监听指定widget;
depth是表示监听的child的深度,第0个即表示NotificationListener child包裹的第一个Widget的滚动,即ListView.
NotificationListener<ScrollNotification>(
// 添加 NotificationListener 作为父容器
onNotification: (scrollNotification) {
// 注册通知回调
if (scrollNotification is ScrollStartNotification &&
scrollNotification.depth == 0) {
// 滚动开始
_listScrollerController.sink.add(true);
} else if (scrollNotification is ScrollUpdateNotification &&
scrollNotification.depth == 0) {
// 滚动位置更新
} else if (scrollNotification is ScrollEndNotification &&
scrollNotification.depth == 0) {
// 滚动结束
_listScrollerController.sink.add(false);
}
return;
},
child: ListView(...)
);









网友评论