-
Notifications
You must be signed in to change notification settings - Fork 56
/
gesture.dart
56 lines (51 loc) · 1.66 KB
/
gesture.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
import 'package:flutter/material.dart';
//手势动作
class GesturePage extends StatefulWidget {
GesturePage(this.title, {Key key}) : super(key: key);
final String title;
@override
_GesturePageState createState() => _GesturePageState();
}
class _GesturePageState extends State<GesturePage> {
String _operation = "没有手势!"; //保存事件名
double _width = 200.0; //通过修改图片宽度来达到缩放效果
double _height = 100.0; //通过修改图片高度来达到缩放效果
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: GestureDetector(
child: Container(
alignment: Alignment.center,
color: Theme.of(context).primaryColor,
width: _width,
height: _height,
child: Text(
_operation,
style: TextStyle(color: Colors.white),
),
),
onTap: () => updateText("点击"), //点击
onDoubleTap: () => updateText("双击"), //双击
onLongPress: () => updateText("长按"), //长按
onScaleUpdate: (ScaleUpdateDetails details) {
setState(() {
//缩放倍数在0.8到10倍之间
_operation = "缩放";
_width = 200 * details.scale.clamp(0.8, 2.0);
_height = 100 * details.scale.clamp(0.8, 2.0);
});
},
),
));
}
void updateText(String text) {
//更新显示的事件名
setState(() {
_operation = text;
});
}
}