@@ -6,19 +6,135 @@ class Index extends StatefulWidget {
66}
77
88class _IndexState extends State <Index > {
9+ bool isOn = false ;
10+ String _value = '' ;
11+ String _value2 = '' ;
912 @override
1013 void initState () {
1114 super .initState ();
1215 }
1316
17+ updateText (txt) {
18+ setState (() {
19+ _value = txt;
20+ });
21+ }
22+
23+ updateText2 (txt) {
24+ setState (() {
25+ _value2 = txt;
26+ });
27+ }
28+
29+
1430 @override
1531 Widget build (BuildContext context) {
1632 return Scaffold (
1733 appBar: AppBar (
1834 title: Text ('GestureDetector' ),
1935 ),
2036 body: Center (
21- child: Text ('更新中' ),
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,
47+ ),
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+ ],
90+ ),
91+ ),
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+ ],
132+ ),
133+ ),
134+ ),
135+ Text (_value2),
136+ ],
137+ ),
22138 ),
23139 );
24140 }
0 commit comments