|
1 | 1 | import 'package:flutter/material.dart'; |
| 2 | +import 'package:random_pk/random_pk.dart' show RandomContainer; |
2 | 3 |
|
3 | 4 | class Index extends StatefulWidget { |
4 | 5 | @override |
@@ -26,114 +27,111 @@ class _IndexState extends State<Index> { |
26 | 27 | }); |
27 | 28 | } |
28 | 29 |
|
29 | | - |
30 | 30 | @override |
31 | 31 | Widget build(BuildContext context) { |
32 | 32 | return Scaffold( |
33 | 33 | appBar: AppBar( |
34 | 34 | title: Text('GestureDetector'), |
35 | 35 | ), |
36 | 36 | body: Center( |
37 | | - child: Column( |
38 | | - children: <Widget>[ |
39 | | - GestureDetector( |
40 | | - onTap: () { |
41 | | - Scaffold.of(context).showSnackBar( |
42 | | - SnackBar(content: Text('you click the button'))); |
43 | | - }, |
44 | | - child: Icon( |
45 | | - Icons.share, |
46 | | - color: Colors.red, |
| 37 | + child: RandomContainer( |
| 38 | + child: Column( |
| 39 | + children: <Widget>[ |
| 40 | + GestureDetector( |
| 41 | + onTap: () { |
| 42 | + Scaffold.of(context).showSnackBar( |
| 43 | + SnackBar(content: Text('you click the button'))); |
| 44 | + }, |
| 45 | + child: Icon( |
| 46 | + Icons.share, |
| 47 | + color: Colors.red, |
| 48 | + ), |
47 | 49 | ), |
48 | | - ), |
49 | | - GestureDetector( |
50 | | - onPanStart: (ev) { |
51 | | - updateText('onPanStart $ev'); |
52 | | - }, |
53 | | - onPanEnd: (ev) { |
54 | | - updateText('onPanEnd $ev'); |
55 | | - }, |
56 | | - onPanCancel: () { |
57 | | - updateText('onPanCancel'); |
58 | | - }, |
59 | | - onPanDown: (ev) { |
60 | | - updateText('onPanDown $ev'); |
61 | | - }, |
62 | | - onPanUpdate: (ev) { |
63 | | - updateText('onPanUpdate $ev'); |
64 | | - }, |
65 | | - onDoubleTap: () { |
66 | | - updateText('onDoubleTap'); |
67 | | - }, |
68 | | - // 连接点击两次的话,不会触发onTap,只会触发 onDoubleTap |
69 | | - onTap: () { |
70 | | - updateText('onTap'); |
71 | | - setState(() { |
72 | | - isOn = !isOn; |
73 | | - }); |
74 | | - }, |
75 | | - child: Container( |
76 | | - alignment: Alignment.center, |
77 | | - height: 100, |
78 | | - width: 200, |
79 | | - color: Colors.blue, |
80 | | - child: Column( |
81 | | - mainAxisAlignment: MainAxisAlignment.center, |
82 | | - children: <Widget>[ |
83 | | - Text('TURN LIGHTS ON'), |
84 | | - Divider(), |
85 | | - Icon( |
86 | | - Icons.lightbulb_outline, |
87 | | - color: isOn ? Colors.yellow : Colors.grey, |
88 | | - ) |
89 | | - ], |
| 50 | + Divider( |
| 51 | + height: 20, |
| 52 | + ), |
| 53 | + GestureDetector( |
| 54 | + onDoubleTap: () { |
| 55 | + updateText('onDoubleTap'); |
| 56 | + }, |
| 57 | + onTapDown: (TapDownDetails e) { |
| 58 | + updateText('onTapDown'); |
| 59 | + print(e.globalPosition); |
| 60 | + }, |
| 61 | + onTapCancel: () { |
| 62 | + updateText('onTapCancel'); |
| 63 | + }, |
| 64 | + // 连接点击两次的话,不会触发onTap,只会触发 onDoubleTap |
| 65 | + onTap: () { |
| 66 | + updateText('onTap'); |
| 67 | + setState(() { |
| 68 | + isOn = !isOn; |
| 69 | + }); |
| 70 | + }, |
| 71 | + child: Container( |
| 72 | + alignment: Alignment.center, |
| 73 | + height: 100, |
| 74 | + width: 200, |
| 75 | + color: Colors.blue, |
| 76 | + child: Column( |
| 77 | + mainAxisAlignment: MainAxisAlignment.center, |
| 78 | + children: <Widget>[ |
| 79 | + Text('TURN LIGHTS ON'), |
| 80 | + Divider(), |
| 81 | + Icon( |
| 82 | + Icons.lightbulb_outline, |
| 83 | + color: isOn ? Colors.yellow : Colors.grey, |
| 84 | + ) |
| 85 | + ], |
| 86 | + ), |
90 | 87 | ), |
91 | 88 | ), |
92 | | - ), |
93 | | - Text(_value), |
94 | | - GestureDetector( |
95 | | - onLongPress: () { |
96 | | - updateText2('onLongPress'); |
97 | | - }, |
98 | | - onForcePressEnd: (ev) { |
99 | | - updateText2('onForcePressEnd ${ev.globalPosition}'); |
100 | | - }, |
101 | | - onForcePressStart: (ev) { |
102 | | - updateText2('onForcePressStart ${ev.globalPosition}'); |
103 | | - }, |
104 | | - onForcePressUpdate: (ev) { |
105 | | - updateText2('onForcePressUpdate ${ev.globalPosition}'); |
106 | | - }, |
107 | | - onForcePressPeak: (ev) { |
108 | | - updateText2('onForcePressPeak ${ev.globalPosition}'); |
109 | | - }, |
110 | | - // 连接点击两次的话,不会触发onTap,只会触发 onDoubleTap |
111 | | - onTap: () { |
112 | | - updateText2('onDoubleTap'); |
113 | | - setState(() { |
114 | | - isOn = !isOn; |
115 | | - }); |
116 | | - }, |
117 | | - child: Container( |
118 | | - alignment: Alignment.center, |
119 | | - height: 100, |
120 | | - width: 200, |
121 | | - color: Colors.blue, |
122 | | - child: Column( |
123 | | - mainAxisAlignment: MainAxisAlignment.center, |
124 | | - children: <Widget>[ |
125 | | - Text('Tap or DoubleTap is not useful'), |
126 | | - Divider(), |
127 | | - Icon( |
128 | | - Icons.lightbulb_outline, |
129 | | - color: isOn ? Colors.yellow : Colors.grey, |
130 | | - ) |
131 | | - ], |
| 89 | + Text(_value), |
| 90 | + Divider( |
| 91 | + height: 20, |
| 92 | + ), |
| 93 | + Text("使用ForcePress相关属性将不会触发Tap属性"), |
| 94 | + GestureDetector( |
| 95 | + onForcePressEnd: (ev) { |
| 96 | + updateText2('onForcePressEnd ${ev.globalPosition}'); |
| 97 | + }, |
| 98 | + onForcePressStart: (ev) { |
| 99 | + updateText2('onForcePressStart ${ev.globalPosition}'); |
| 100 | + }, |
| 101 | + onForcePressUpdate: (ev) { |
| 102 | + updateText2('onForcePressUpdate ${ev.globalPosition}'); |
| 103 | + }, |
| 104 | + onForcePressPeak: (ev) { |
| 105 | + updateText2('onForcePressPeak ${ev.globalPosition}'); |
| 106 | + }, |
| 107 | + // 连接点击两次的话,不会触发onTap,只会触发 onDoubleTap |
| 108 | + onTap: () { |
| 109 | + updateText2('onTap'); |
| 110 | + setState(() { |
| 111 | + isOn = !isOn; |
| 112 | + }); |
| 113 | + }, |
| 114 | + child: Container( |
| 115 | + alignment: Alignment.center, |
| 116 | + height: 100, |
| 117 | + width: 200, |
| 118 | + color: Colors.blue, |
| 119 | + child: Column( |
| 120 | + mainAxisAlignment: MainAxisAlignment.center, |
| 121 | + children: <Widget>[ |
| 122 | + Text('Tap or DoubleTap is not useful'), |
| 123 | + Divider(), |
| 124 | + Icon( |
| 125 | + Icons.lightbulb_outline, |
| 126 | + color: isOn ? Colors.yellow : Colors.grey, |
| 127 | + ) |
| 128 | + ], |
| 129 | + ), |
132 | 130 | ), |
133 | 131 | ), |
134 | | - ), |
135 | | - Text(_value2), |
136 | | - ], |
| 132 | + Text(_value2), |
| 133 | + ], |
| 134 | + ), |
137 | 135 | ), |
138 | 136 | ), |
139 | 137 | ); |
|
0 commit comments