|
@@ -1,6 +1,7 @@
|
1
|
1
|
import 'dart:async';
|
2
|
|
-
|
3
|
|
-import 'package:farmer_client/components/UI/DefaultButton.dart';
|
|
2
|
+import 'dart:ffi';
|
|
3
|
+import 'package:fluttertoast/fluttertoast.dart';
|
|
4
|
+import 'package:flutter/gestures.dart';
|
4
|
5
|
import 'package:flutter/material.dart';
|
5
|
6
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
6
|
7
|
|
|
@@ -13,36 +14,26 @@ class MyRouteLogin extends StatefulWidget {
|
13
|
14
|
}
|
14
|
15
|
|
15
|
16
|
class _RouteLogin extends State<MyRouteLogin> {
|
|
17
|
+ @override
|
|
18
|
+ void initState() {
|
|
19
|
+ super.initState();
|
|
20
|
+ //注册协议的手势
|
|
21
|
+ }
|
|
22
|
+
|
16
|
23
|
bool isButtonEnable = true; //按钮状态 是否可点击
|
17
|
24
|
String buttonText = '发送验证码'; //初始文本
|
18
|
|
- int count = 5; //初始倒计时时间
|
|
25
|
+ int count = 60; //初始倒计时时间
|
19
|
26
|
var timer; //倒计时的计时器
|
20
|
27
|
TextEditingController mController = TextEditingController();
|
21
|
|
- void _buttonClickListen() {
|
22
|
|
- print('获取验证码按钮');
|
23
|
|
- setState(() {
|
24
|
|
- if (isButtonEnable) {
|
25
|
|
- //当按钮可点击时
|
26
|
|
- isButtonEnable = false; //按钮状态标记
|
27
|
|
- _initTimer();
|
28
|
|
- getSMSCaptch(handlePhones);
|
29
|
|
- return null; //返回null按钮禁止点击
|
30
|
|
- } else {
|
31
|
|
- //当按钮不可点击时
|
32
|
|
-// debugPrint('false');
|
33
|
|
- return null; //返回null按钮禁止点击
|
34
|
|
- }
|
35
|
|
- });
|
36
|
|
- }
|
37
|
28
|
|
38
|
29
|
void _initTimer() {
|
39
|
|
- timer = new Timer.periodic(Duration(seconds: 1), (Timer timer) {
|
|
30
|
+ timer = Timer.periodic(Duration(seconds: 1), (Timer timer) {
|
40
|
31
|
count--;
|
41
|
32
|
setState(() {
|
42
|
33
|
if (count == 0) {
|
43
|
34
|
timer.cancel(); //倒计时结束取消定时器
|
44
|
35
|
isButtonEnable = true; //按钮可点击
|
45
|
|
- count = 5; //重置时间
|
|
36
|
+ count = 60; //重置时间
|
46
|
37
|
buttonText = '发送验证码'; //重置按钮文本
|
47
|
38
|
} else {
|
48
|
39
|
buttonText = '重新发送($count)'; //更新文本内容
|
|
@@ -57,6 +48,8 @@ class _RouteLogin extends State<MyRouteLogin> {
|
57
|
48
|
timer = null;
|
58
|
49
|
mController.dispose();
|
59
|
50
|
super.dispose();
|
|
51
|
+
|
|
52
|
+ ///销毁
|
60
|
53
|
}
|
61
|
54
|
|
62
|
55
|
// -------------逻辑分割-------------------------------------------
|
|
@@ -81,240 +74,236 @@ class _RouteLogin extends State<MyRouteLogin> {
|
81
|
74
|
print('我输入的信息:${userContent},手机号:${userContent['phones']}')
|
82
|
75
|
};
|
83
|
76
|
|
|
77
|
+ bool _checkValue = false;
|
|
78
|
+ bool _newValue = false;
|
|
79
|
+
|
|
80
|
+ void _buttonClickListen() {
|
|
81
|
+ setState(() {
|
|
82
|
+ if (isButtonEnable) {
|
|
83
|
+ if (handlePhones != '') {
|
|
84
|
+ isButtonEnable = false; //按钮状态标记
|
|
85
|
+ _initTimer();
|
|
86
|
+ getSMSCaptch(handlePhones);
|
|
87
|
+ } else {
|
|
88
|
+ Fluttertoast.showToast(msg: '请正确输入手机号!');
|
|
89
|
+ }
|
|
90
|
+
|
|
91
|
+ print('获取验证码按钮222222');
|
|
92
|
+ }
|
|
93
|
+ });
|
|
94
|
+ }
|
|
95
|
+
|
84
|
96
|
@override
|
85
|
97
|
Widget build(BuildContext context) {
|
86
|
98
|
return Container(
|
87
|
|
-
|
88
|
|
- decoration: const BoxDecoration(
|
89
|
|
- image: DecorationImage(
|
90
|
|
- image: AssetImage("images/icon_login.png"),
|
91
|
|
- fit: BoxFit.cover,
|
92
|
|
- ),
|
|
99
|
+ width: 250,
|
|
100
|
+ height: 250,
|
|
101
|
+ decoration: const BoxDecoration(
|
|
102
|
+ image: DecorationImage(
|
|
103
|
+ image: AssetImage("images/icon_login.png"),
|
|
104
|
+ fit: BoxFit.cover,
|
93
|
105
|
),
|
94
|
|
- child: Scaffold(
|
95
|
|
- backgroundColor: Colors.transparent, //把scaffold的背景色改成透明
|
96
|
|
- appBar: AppBar(
|
97
|
|
- backgroundColor: Colors.transparent, //把appbar的背景色改成透明
|
98
|
|
- // elevation: 0,//appbar的阴影
|
99
|
|
- title: const Text('登陆'),
|
100
|
|
- ),
|
101
|
|
- body: Center(
|
102
|
|
- child: ListView(
|
103
|
|
- // crossAxisAlignment: CrossAxisAlignment.start,
|
104
|
|
- children: <Widget>[
|
|
106
|
+ ),
|
105
|
107
|
|
106
|
|
- const Text(
|
107
|
|
- '您好!',
|
108
|
|
- style: TextStyle(
|
109
|
|
- fontWeight: FontWeight.bold,
|
110
|
|
- fontSize: 50,
|
111
|
|
- ),
|
|
108
|
+ child: Scaffold(
|
|
109
|
+ backgroundColor: Colors.transparent, //把scaffold的背景色改成透明
|
|
110
|
+ body: Center(
|
|
111
|
+ child: Column(
|
|
112
|
+ mainAxisAlignment: MainAxisAlignment.end,
|
|
113
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
114
|
+ children:[
|
|
115
|
+ const Text(
|
|
116
|
+ '您好!',
|
|
117
|
+ style: TextStyle(
|
|
118
|
+ fontWeight: FontWeight.bold,
|
|
119
|
+ fontSize: 50,
|
112
|
120
|
),
|
113
|
|
- const Text(
|
114
|
|
- '欢迎进入农户端应用!',
|
115
|
|
- style: TextStyle(
|
116
|
|
- fontWeight: FontWeight.bold,
|
117
|
|
- fontSize: 35,
|
118
|
|
- ),
|
|
121
|
+ ),
|
|
122
|
+ const Text(
|
|
123
|
+ '欢迎进入农户端应用!',
|
|
124
|
+ style: TextStyle(
|
|
125
|
+ fontWeight: FontWeight.bold,
|
|
126
|
+ fontSize: 35,
|
119
|
127
|
),
|
|
128
|
+ ),
|
120
|
129
|
|
121
|
|
- // Container(
|
122
|
|
- // // margin: EdgeInsets.fromLTRB(5,0,0,0),
|
123
|
|
- // decoration: BoxDecoration(
|
124
|
|
- // border: Border(
|
125
|
|
- // bottom: BorderSide(
|
126
|
|
- // width: 1, color: Color(0xffe5e5e5)))),
|
127
|
|
- // child: Flex(
|
128
|
|
- // direction: Axis.horizontal,
|
129
|
|
- // children: <Widget>[
|
130
|
|
- // Expanded(
|
131
|
|
- // child: TextField(
|
132
|
|
- // autofocus: true,
|
133
|
|
- // maxLength: 11,
|
134
|
|
- // keyboardType: TextInputType.number,
|
135
|
|
- // cursorColor: Color(0xD4D4D4FF),
|
136
|
|
- // decoration: const InputDecoration(
|
137
|
|
- // contentPadding:EdgeInsets.fromLTRB(30.0, 0, 0, 0),
|
138
|
|
- // hintText: "请输入手机号",
|
139
|
|
- // prefixIcon: Icon(Icons.phone_iphone_outlined),
|
140
|
|
- // counterText: '',
|
141
|
|
- // border: OutlineInputBorder(
|
142
|
|
- // borderSide: BorderSide.none),
|
143
|
|
- // ),
|
144
|
|
- // onChanged: (e) {
|
145
|
|
- // _handlePhone(e);
|
146
|
|
- // // phoneUser(e);
|
147
|
|
- // },
|
148
|
|
- // ),
|
149
|
|
- // ),
|
150
|
|
- // Container(
|
151
|
|
- // width: 100.0,
|
152
|
|
- // child: SizedBox(
|
153
|
|
- // child: FlatButton(
|
154
|
|
- // disabledColor:
|
155
|
|
- // Colors.grey.withOpacity(0.1), //按钮禁用时的颜色
|
156
|
|
- // disabledTextColor: Colors.white, //按钮禁用时的文本颜色
|
157
|
|
- // textColor: isButtonEnable
|
158
|
|
- // ? Colors.white
|
159
|
|
- // : Colors.black.withOpacity(0.2), //文本颜色
|
160
|
|
- // color: isButtonEnable
|
161
|
|
- // ? Color(0xffff703b)
|
162
|
|
- // : Colors.grey.withOpacity(0.1), //按钮的颜色
|
163
|
|
- // splashColor: isButtonEnable
|
164
|
|
- // ? Colors.white.withOpacity(0.1)
|
165
|
|
- // : Colors.transparent,
|
166
|
|
- // shape: StadiumBorder(side: BorderSide.none),
|
167
|
|
- // onPressed: () {
|
168
|
|
- // setState(() {
|
169
|
|
- // if (isButtonEnable) {
|
170
|
|
- // _buttonClickListen();
|
171
|
|
- // } else {
|
172
|
|
- // return;
|
173
|
|
- // }
|
174
|
|
- // });
|
175
|
|
- // },
|
176
|
|
- // child: Text(
|
177
|
|
- // '$buttonText',
|
178
|
|
- // style: TextStyle(
|
179
|
|
- // fontSize: 13,
|
180
|
|
- //
|
181
|
|
- // ),
|
182
|
|
- // ),
|
183
|
|
- // ),
|
184
|
|
- // ),
|
185
|
|
- // ),
|
186
|
|
- // ],
|
187
|
|
- // )),
|
188
|
|
-
|
189
|
|
- Cell(
|
|
130
|
+ Cell(
|
190
|
131
|
// margin: EdgeInsets.symmetric(horizontal: 13.w),
|
191
|
|
- margin: const EdgeInsets.fromLTRB(13, 43, 10,0 ),
|
|
132
|
+ margin: const EdgeInsets.fromLTRB(13, 43, 10, 0),
|
192
|
133
|
header: Text(
|
193
|
134
|
"+86",
|
194
|
|
- style: TextStyle(fontSize: 19.sp,),
|
195
|
|
- ),
|
196
|
|
- child: TextField(
|
197
|
|
- maxLength: 11,
|
198
|
|
- keyboardType: TextInputType.number,
|
199
|
|
- style: TextStyle(
|
200
|
|
- fontSize: 17.sp,
|
201
|
|
- ),
|
202
|
|
- decoration: const InputDecoration(
|
203
|
|
- isCollapsed: true,
|
204
|
|
- contentPadding:
|
205
|
|
- EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
206
|
|
- labelText: "请输入手机号码",
|
207
|
|
- counterText: '',//去掉计数
|
208
|
|
- border: InputBorder.none,
|
209
|
|
- floatingLabelBehavior: FloatingLabelBehavior.never,
|
210
|
|
- ),
|
211
|
|
- onChanged: (e) {
|
212
|
|
- _handlePhone(e);
|
213
|
|
- },
|
214
|
|
- ),
|
215
|
|
- footer: ElevatedButton(
|
216
|
|
- onPressed: () => {
|
217
|
|
- setState(() {
|
218
|
|
- if (isButtonEnable) {
|
219
|
|
- _buttonClickListen();
|
220
|
|
- } else {
|
221
|
|
- return;
|
222
|
|
- }
|
223
|
|
- })
|
224
|
|
- },
|
225
|
|
- child: Text(
|
226
|
|
- '$buttonText',
|
227
|
|
- style: TextStyle(fontSize: 15.sp),
|
228
|
|
- ),
|
229
|
|
- style: ElevatedButton.styleFrom(
|
230
|
|
- primary: const Color(0xFFFF703B),
|
231
|
|
- elevation: 0,
|
232
|
|
- shape: const RoundedRectangleBorder(
|
233
|
|
- borderRadius:
|
234
|
|
- BorderRadius.all(Radius.circular(10)))),
|
235
|
|
- ),
|
236
|
|
- ),
|
237
|
|
-// --------------FractionalOffset API--------------
|
238
|
|
-// FractionalOffset(0.0, 0.0):顶部左边
|
239
|
|
-// FractionalOffset(0.5, 0.0):顶部中间
|
240
|
|
-// FractionalOffset(1.0, 0.0):顶部右边
|
241
|
|
-// FractionalOffset(0.0, 0.5):中部左边
|
242
|
|
-// FractionalOffset(0.5, 0.5):中部中间
|
243
|
|
-// FractionalOffset(1.0, 0.5):中部右边
|
244
|
|
-// FractionalOffset(0.0, 1.0):底部左边
|
245
|
|
-// FractionalOffset(0.5, 1.0):底部中间
|
246
|
|
-// FractionalOffset(1.0, 1.0):底部右边
|
247
|
|
-
|
248
|
|
- Cell(
|
249
|
|
- // margin: EdgeInsets.symmetric(horizontal: 13.w),
|
250
|
|
- margin: const EdgeInsets.fromLTRB(13, 16, 10,0 ),
|
251
|
|
-
|
252
|
|
- header: Align(
|
253
|
|
- alignment: FractionalOffset(0.1, 0.5),
|
254
|
|
- child: Image.asset(
|
255
|
|
- 'images/phoneCode.png',
|
256
|
|
- width: 20,
|
257
|
|
- height: 20,
|
|
135
|
+ style: TextStyle(
|
|
136
|
+ fontSize: 19.sp,
|
258
|
137
|
),
|
259
|
138
|
),
|
260
|
|
-
|
261
|
139
|
child: TextField(
|
|
140
|
+ maxLength: 11,
|
262
|
141
|
keyboardType: TextInputType.number,
|
263
|
142
|
style: TextStyle(
|
264
|
143
|
fontSize: 17.sp,
|
265
|
|
-
|
266
|
144
|
),
|
267
|
145
|
decoration: const InputDecoration(
|
268
|
146
|
isCollapsed: true,
|
269
|
|
-
|
270
|
147
|
contentPadding:
|
271
|
|
- EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
272
|
|
- labelText: "请输入验证码",
|
|
148
|
+ EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
|
149
|
+ labelText: "请输入手机号码",
|
|
150
|
+ counterText: '', //去掉计数
|
273
|
151
|
border: InputBorder.none,
|
274
|
152
|
floatingLabelBehavior: FloatingLabelBehavior.never,
|
275
|
153
|
),
|
276
|
154
|
onChanged: (e) {
|
277
|
|
- _handleCode(e);
|
|
155
|
+ _handlePhone(e);
|
278
|
156
|
},
|
279
|
157
|
),
|
|
158
|
+ footer: SizedBox(
|
|
159
|
+ width: 300.w,
|
|
160
|
+ child: ElevatedButton(
|
|
161
|
+ onPressed: () => {
|
|
162
|
+ setState(() {
|
|
163
|
+ // _buttonClickListen();
|
|
164
|
+ setState(() {
|
|
165
|
+ if (isButtonEnable) {
|
|
166
|
+ if (handlePhones != '') {
|
|
167
|
+ isButtonEnable = false; //按钮状态标记
|
|
168
|
+ _initTimer();
|
|
169
|
+ getSMSCaptch(handlePhones);
|
|
170
|
+ } else {
|
|
171
|
+ Fluttertoast.showToast(msg: '请正确输入手机号!');
|
|
172
|
+ }
|
280
|
173
|
|
281
|
|
- ),
|
|
174
|
+ print('获取验证码按钮222222');
|
|
175
|
+ }
|
|
176
|
+ });
|
282
|
177
|
|
|
178
|
+ })
|
|
179
|
+ },
|
|
180
|
+ child: Text(
|
|
181
|
+ '$buttonText',
|
|
182
|
+ style: TextStyle(
|
|
183
|
+ fontSize: 15.sp,
|
|
184
|
+ ),
|
|
185
|
+ ),
|
|
186
|
+ style: ButtonStyle(
|
|
187
|
+ backgroundColor: isButtonEnable
|
|
188
|
+ ? MaterialStateProperty.all(const Color(0xFFFF703B))
|
|
189
|
+ : MaterialStateProperty.all(
|
|
190
|
+ const Color(0xFFCBCBCB)),
|
|
191
|
+ shape: MaterialStateProperty.all(
|
|
192
|
+ const RoundedRectangleBorder(
|
|
193
|
+ borderRadius:
|
|
194
|
+ BorderRadius.all(Radius.circular(10)))),
|
|
195
|
+ ),
|
|
196
|
+ ),
|
|
197
|
+ )),
|
|
198
|
+// --------------FractionalOffset API--------------
|
283
|
199
|
|
|
200
|
+ Cell(
|
|
201
|
+ // margin: EdgeInsets.symmetric(horizontal: 13.w),
|
|
202
|
+ margin: const EdgeInsets.fromLTRB(13, 16, 10, 0),
|
284
|
203
|
|
|
204
|
+ header: Align(
|
|
205
|
+ alignment: FractionalOffset(0.1, 0.5),
|
|
206
|
+ child: Image.asset(
|
|
207
|
+ 'images/phoneCode.png',
|
|
208
|
+ width: 20,
|
|
209
|
+ height: 20,
|
|
210
|
+ ),
|
|
211
|
+ ),
|
285
|
212
|
|
286
|
|
- // TextField(
|
287
|
|
- // style: TextStyle(
|
288
|
|
- // fontSize: 17.sp,
|
289
|
|
- // ),
|
290
|
|
- // keyboardType: TextInputType.number,
|
291
|
|
- // cursorColor: Color(0xD4D4D4FF),
|
292
|
|
- // decoration: const InputDecoration(
|
293
|
|
- // contentPadding:
|
294
|
|
- // EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
295
|
|
- // labelText: "请输入验证码",
|
296
|
|
- // prefixIcon: Icon(Icons.beenhere)),
|
297
|
|
- // onChanged: (e) {
|
298
|
|
- // _handleCode(e);
|
299
|
|
- // },
|
300
|
|
- // ),
|
301
|
|
- // 登录按钮
|
302
|
|
- Center(
|
303
|
|
- child: DefaultButton(
|
304
|
|
- margin: const EdgeInsets.fromLTRB(0, 30.0, 0, 0), //可选配置,自定义控件中有默认配置
|
305
|
|
- text: "登陆",
|
306
|
|
- width: 90.0,
|
307
|
|
- height: 50.0,
|
308
|
|
- fontSize: 20.0,
|
309
|
|
- backColor: const Color(0xffff703b),
|
310
|
|
- color: Colors.white,
|
311
|
|
- onPressed: () {
|
312
|
|
- },
|
313
|
|
- ),
|
314
|
|
- ) ,
|
|
213
|
+ child: TextField(
|
|
214
|
+ keyboardType: TextInputType.number,
|
|
215
|
+ style: TextStyle(
|
|
216
|
+ fontSize: 17.sp,
|
|
217
|
+ ),
|
|
218
|
+ decoration: const InputDecoration(
|
|
219
|
+ isCollapsed: true,
|
|
220
|
+ contentPadding:
|
|
221
|
+ EdgeInsets.symmetric(vertical: 8, horizontal: 16),
|
|
222
|
+ labelText: "请输入验证码",
|
|
223
|
+ border: InputBorder.none,
|
|
224
|
+ floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
225
|
+ ),
|
|
226
|
+ onChanged: (e) {
|
|
227
|
+ _handleCode(e);
|
|
228
|
+ },
|
|
229
|
+ ),
|
|
230
|
+ ),
|
315
|
231
|
|
|
232
|
+ Container(
|
|
233
|
+ height: 350.h,
|
|
234
|
+ alignment: Alignment.bottomCenter,
|
|
235
|
+ child: SizedBox(
|
|
236
|
+ width: 315.w,
|
|
237
|
+ height: 49.h,
|
|
238
|
+ child: ElevatedButton(
|
|
239
|
+ onPressed: () {
|
|
240
|
+ if(handleCodes==''||handlePhones==''){
|
|
241
|
+ Fluttertoast.showToast(msg: '请输入验证码或手机号!');
|
|
242
|
+ }else{
|
|
243
|
+ if(_newValue){
|
|
244
|
+ print('已同意协议');
|
|
245
|
+ }else{
|
|
246
|
+ Fluttertoast.showToast(msg: '请阅读并同意相关隐私政策!');
|
|
247
|
+ }
|
|
248
|
+ }
|
|
249
|
+ },
|
|
250
|
+ child: const Text(
|
|
251
|
+ "登陆",
|
|
252
|
+ style: TextStyle(
|
|
253
|
+ fontSize: 18,
|
|
254
|
+ color: Colors.white,
|
|
255
|
+ fontWeight: FontWeight.bold),
|
|
256
|
+ ),
|
|
257
|
+ style: ButtonStyle(
|
|
258
|
+ backgroundColor:
|
|
259
|
+ MaterialStateProperty.all(const Color(0xFFFF703B)),
|
|
260
|
+ shape: MaterialStateProperty.all(
|
|
261
|
+ const RoundedRectangleBorder(
|
|
262
|
+ borderRadius:
|
|
263
|
+ BorderRadius.all(Radius.circular(24.4)))),
|
|
264
|
+ ),
|
|
265
|
+ ),
|
|
266
|
+ ),
|
|
267
|
+ ),
|
316
|
268
|
|
317
|
|
- ],
|
318
|
|
- ))));
|
|
269
|
+ Padding(
|
|
270
|
+ padding: EdgeInsets.fromLTRB(10.0, 10, 10.0, 10),
|
|
271
|
+ child: Row(
|
|
272
|
+ children: <Widget>[
|
|
273
|
+ Radio<bool>(
|
|
274
|
+ value: true,
|
|
275
|
+ activeColor: Color(0xFFFF703B),
|
|
276
|
+ groupValue: _newValue,
|
|
277
|
+ onChanged: (value) {
|
|
278
|
+ setState(() {
|
|
279
|
+ _newValue = value!;
|
|
280
|
+ });
|
|
281
|
+ }),
|
|
282
|
+ RichText(
|
|
283
|
+ text: TextSpan(children: <InlineSpan>[
|
|
284
|
+ TextSpan(
|
|
285
|
+ text: '请认真查看',
|
|
286
|
+ style: TextStyle(color: Color(0xff2a2a2a))),
|
|
287
|
+ TextSpan(
|
|
288
|
+ text: '文本协议/隐私政策,',
|
|
289
|
+ style: TextStyle(color: Color(0xffce3800)),
|
|
290
|
+ recognizer:
|
|
291
|
+ TapGestureRecognizer() //踩坑。。。recognizer 是手势交互 除了我现在些的是 点击交互,其他一般都是抽象类。
|
|
292
|
+ ..onTap = () {
|
|
293
|
+ print('阅读已同意!!!');
|
|
294
|
+ },
|
|
295
|
+ ),
|
|
296
|
+ TextSpan(
|
|
297
|
+ text: '确认之后选择此项',
|
|
298
|
+ style: TextStyle(color: Color(0xff2a2a2a))),
|
|
299
|
+ ]),
|
|
300
|
+ ),
|
|
301
|
+ ],
|
|
302
|
+ )),
|
|
303
|
+ ],
|
|
304
|
+ ),
|
|
305
|
+ ),
|
|
306
|
+ ),
|
|
307
|
+ );
|
319
|
308
|
}
|
320
|
309
|
}
|