Flutter-滑动冲突处理
本文最后更新于 391 天前

1. 定义NotificationListener

Widget wrapWithNotify(Widget child){
    return NotificationListener<ScrollNotification>(
        child: child,
        onNotification: handleNotification,
    );
}

2. 具体处理

bool handleNotification(ScrollNotification notification){
    final ScrollMetrics metrics = notification.metrics;

    if(metrics.axis == Axis.horizontal){
        if(notification is ScrollEndNotification){
            log('end');
            //drag = null;
            dragPosition = null;
            onEdge = metrics.atEdge;
            //        if(metrics.atEdge){
            //          log(' at edge');
            //          if(drag == null ){
            //            drag = pageController.position.drag(dragStartDetails, () {
            //              //drag = null;
            //            });
            //            drag.cancel();
            //          }
            //        }
            return true;
        }
        if(notification is ScrollStartNotification){
            log('start');
            onEdge = metrics.atEdge;
            if(notification.dragDetails == null) return true;
            dragStartDetails = notification.dragDetails;
            return true;
        }
        if(notification is ScrollUpdateNotification){
            onEdge = metrics.atEdge;
        }
        if(notification is OverscrollNotification){
            //        if(notification.dragDetails == null) return true;
            //        drag.update(notification.dragDetails);
            log('onEdge');
            if(!onEdge) return true;
            drag = pageController.position.drag(dragStartDetails, () {
                //drag = null;
            });
            onEdge = false;
        }
        ///滑动到边缘,例如最小边缘时,继续向右滑动,此时不会触发update
        ///只会触发 start和 end
        //      if(notification is ScrollUpdateNotification){
        //        log('update');
        ////        log('after  :{metrics.extentAfter}');
        ////        log('before : ${metrics.extentBefore}');
        //      }

        //      if(notification is UserScrollNotification){
        //        log('user');
        //        if(metrics.pixels == metrics.minScrollExtent && notification.direction == ScrollDirection.forward){
        //          if(drag == null ){
        //            drag = pageController.position.drag(dragStartDetails, () {
        //              drag = null;
        //            });
        //          }
        //
        //        }else if(metrics.pixels == metrics.maxScrollExtent && notification.direction == ScrollDirection.reverse){
        //          if(drag == null ){
        //            drag = pageController.position.drag(dragStartDetails, () {
        //              drag = null;
        //            });
        //          }
        //        }
        //
        //      }
    }
    return true;
}
iichen:https://iichen.cn/?p=718
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇