美文网首页
flutter-ListView的上下滚动监听(左右轮播响应)问

flutter-ListView的上下滚动监听(左右轮播响应)问

作者: 浮华_du | 来源:发表于2021-03-29 17:11 被阅读0次

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(...)
);

相关文章

网友评论

      本文标题:flutter-ListView的上下滚动监听(左右轮播响应)问

      本文链接:https://www.haomeiwen.com/subject/dpibhltx.html