- GestureDetector,RawGestureDetector都是继承自StatelessWidget;
- 都是监听子组件中手势事件;
- 同样都是对Pointer的封装;
- 使用前都需要
import 'package:flutter/gestures.dart';
;
顾名思义RawGestureDetector就是未加工的GestureDetector,使用起来稍微会一点麻烦。
代码语言:javascript复制//无法热更新
//Transform.translate() 使用系统已封装好的,使组件在X、Y轴移动的方法。
//Transform.scale() 比例变换
//Transform.rotate() 角度变换
Transform.translate(
offset: Offset(0.0, this._offDistance),
child: RawGestureDetector(
gestures: <Type, GestureRecognizerFactory>{
//垂直移动VerticalDragGestureRecognizer
//水平移动HorizontalDragGestureRecognizer
//长按PanGestureRecognizer
VerticalDragGestureRecognizer:
GestureRecognizerFactoryWithHandlers
<VerticalDragGestureRecognizer>(
()=>VerticalDragGestureRecognizer(),
(VerticalDragGestureRecognizer _initial) {
_initial
..onStart = (DragStartDetails details) {
print('开始');
}
..onUpdate = (DragUpdateDetails details) {
print('正在移动');
}
..onEnd = (DragEndDetails details){
print('结束');};}),},
child: widget.child,))