美文网首页
Flutter——事件监听

Flutter——事件监听

作者: 刘铁崧 | 来源:发表于2020-12-09 18:14 被阅读0次

    1.原始指针用Pointer监听

    • 案例:
     body: Center(
            child: Listener(
              child: Container(width: 100,height: 100,color: Colors.red),
              onPointerDown: (event){
                print(event.position);
                print(event.localPosition);
              },
            )
          ),
    

    2.手势监听

    • 案例
          body: Center(
            child: GestureDetector(
              onTapDown: (gesture){
                print(gesture.localPosition);
                print(gesture.globalPosition);
              },
              child: Container(
                height: 100,
                width: 100,
                color: Colors.red,
              ),
            )
          ),
    

    原码属性

        this.child,
        this.onTapDown,
        this.onTapUp,
        this.onTap,
        this.onTapCancel,
        this.onSecondaryTap,
        this.onSecondaryTapDown,
        this.onSecondaryTapUp,
        this.onSecondaryTapCancel,
        this.onDoubleTap,
        this.onLongPress,
        this.onLongPressStart,
        this.onLongPressMoveUpdate,
        this.onLongPressUp,
        this.onLongPressEnd,
        this.onSecondaryLongPress,
        this.onSecondaryLongPressStart,
        this.onSecondaryLongPressMoveUpdate,
        this.onSecondaryLongPressUp,
        this.onSecondaryLongPressEnd,
        this.onVerticalDragDown,
        this.onVerticalDragStart,
        this.onVerticalDragUpdate,
        this.onVerticalDragEnd,
        this.onVerticalDragCancel,
        this.onHorizontalDragDown,
        this.onHorizontalDragStart,
        this.onHorizontalDragUpdate,
        this.onHorizontalDragEnd,
        this.onHorizontalDragCancel,
        this.onForcePressStart,
        this.onForcePressPeak,
        this.onForcePressUpdate,
        this.onForcePressEnd,
        this.onPanDown,
        this.onPanStart,
        this.onPanUpdate,
        this.onPanEnd,
        this.onPanCancel,
        this.onScaleStart,
        this.onScaleUpdate,
        this.onScaleEnd,
    

    Tap
    onTapDown 指针已经在特定位置与屏幕接触
    onTapUp 指针停止在特定位置与屏幕接触
    onTap tap事件触发
    onTapCancel 先前指针触发的onTapDown不会在触发tap事件
    双击
    onDoubleTap 用户快速连续两次在同一位置轻敲屏幕.
    长按
    onLongPress 指针在相同位置长时间保持与屏幕接触
    垂直拖动
    onVerticalDragStart 指针已经与屏幕接触并可能开始垂直移动
    onVerticalDragUpdate 指针与屏幕接触并已沿垂直方向移动.
    onVerticalDragEnd 先前与屏幕接触并垂直移动的指针不再与屏幕接触,并且在停止接触屏幕时以特定速度移动
    水平拖动
    onHorizontalDragStart 指针已经接触到屏幕并可能开始水平移动
    onHorizontalDragUpdate 指针与屏幕接触并已沿水平方向移动
    onHorizontalDragEnd 先前与屏幕接触并水平移动的指针不再与屏幕接触,并在停止接触屏幕时以特定速度移动

    相关文章

      网友评论

          本文标题:Flutter——事件监听

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