瞎扯
不管是android还是前端,
都会有点击事件.
在flutter里面也一样.
关键的类:GestureDetector-手势检测
GestureDetector
在flutter.这个容器,就是专门用来处理手势的
其实在android也有这个类,但是了解的人应该不多.我就没怎么用.哈哈
this.child, //包裹的weight
this.onTapDown, //抬起
this.onTapUp, //按下
this.onTap, //点击回调
this.onTapCancel, //事件结束
this.onDoubleTap, //双击
this.onLongPress, //长按
this.onLongPressUp, //长按抬起
this.onVerticalDragDown, //当一个触摸点开始跟屏幕交互,同时在垂直方向上移动时触发
this.onVerticalDragStart, //同上,开始
this.onVerticalDragUpdate, //同上,移动
this.onVerticalDragEnd, //同上,停止
this.onVerticalDragCancel, //同上,用户突然停止拖拽时触发
this.onHorizontalDragDown,//水平,同onVerticalDragDown
this.onHorizontalDragStart,//水平,同onVerticalDragStart
this.onHorizontalDragUpdate,//水平,同onVerticalDragUpdate
this.onHorizontalDragEnd,//水平,同onVerticalDragEnd
this.onHorizontalDragCancel,//水平,同onVerticalDragCancel
this.onPanDown,// 当触摸点开始跟屏幕交互时触发
this.onPanStart,// 当触摸点开始移动时触发
this.onPanUpdate,// 同上,移动更新
this.onPanEnd,// 同上,停止
this.onPanCancel,// 同上,突然停止,抬起
this.onScaleStart, //抬起,同时会建立一个焦点为1.0
this.onScaleUpdate,//抬起,同时会标示一个新的焦点
this.onScaleEnd,//抬起,同时也表示这个scale手势完成
this.behavior,
this.excludeFromSemantics = false
具体属性如上,
其实大多数时都只会用到onTap,或者onDoubleTap,onLongPress.
其他的基本是自定义的时候才会用,
使用
Widget build(BuildContext context) {
return Row(
children: <Widget>[
new GestureDetector(
child: content(),
onTap: () {
print('单击打印');
},
onDoubleTap: () {
print('双击打印');
},
),
],
);
}
基本上就这么简单.而且基本也只有这一种写法.
如果你想和android一样,
view.setOnClickListener(this)
只能说,没戏.哈哈
image.png image.png源码里这个 onTap
只是个方法声明而已.不算接口.也就不存在实现的问题了.
而且,也不会把点击的weight通过形参传进回调里.
dart里其实也没有纯接口的概念,只有类和多继承,
交流群:493180098,这是个很少吹水,交流学习的群.
APP开发维护咨询群 : 492685472 ,承接APP迭代.开发维护.咨询业务,付费快速解决问题.
网友评论