美文网首页
Flutter-手势探测器的长按事件

Flutter-手势探测器的长按事件

作者: 阿博聊编程 | 来源:发表于2022-06-15 07:07 被阅读0次
配图来自网络,如侵必删

我们在接触到FlutterGestureDetector之后,肯定会想实现长按事件的需求。这篇博客来分享GestureDetector的长按事件,希望对看文章的小伙伴有所启发。

长按事件的属性

事件API 事件描述
onLongPress 手指在屏幕长按一定时间后触发的事件
onLongPressStart 长按事件的开始
onLongPressEnd 长按事件的结束
onLongPressMoveUpdate 长按事件中的手指移动触发的回调

长按主要有4种事件,我们可以监听。下面是简单的使用代码示例:

GestureDetector(
        onLongPress: () {
          print('onLongPress 长按事件');
        },
        onLongPressStart: (LongPressStartDetails details) {
          print('长按在' + details.globalPosition.toString() + "位置上开始发生");
        },
        child: Container(
          width: 100,
          height: 100,
          color: Colors.redAccent,
          child: const Text(
            '长按',
            style: TextStyle(
              color: Colors.white,
            ),
          ),
        ),
      ),

这个代码是可以直接复制到编译器使用的,在使用onLongPressStartonLongPressEndonLongPressMoveUpdate的长按事件的需要使用到LongPressXXXDetails对象。

相关文章

网友评论

      本文标题:Flutter-手势探测器的长按事件

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