login_page.dart
15 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/app.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/utils/navigator_util.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:provider/provider.dart';
class LoginPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return new LoginState();
}
}
class LoginState extends State<LoginPage> with WidgetsBindingObserver{
TextEditingController _sellerCodeController=TextEditingController();
TextEditingController _accountController = TextEditingController();
final TextEditingController _pwdController = TextEditingController();
final ScrollController _scrollController=new ScrollController();
final FocusNode _sellerCodeFocusNode=new FocusNode();
final FocusNode _accountFocusNode=new FocusNode();
final FocusNode _pwdFocusNode=new FocusNode();
bool obscureText=true;//是否隐藏密码
bool isActivate=false;//是否激活登录
String errorText="";//错误提示
bool _check = true;
@override
void initState(){
// TODO: implement initState
super.initState();
isLogin();
WidgetsBinding.instance.addObserver(this);
WidgetsBinding.instance.addPostFrameCallback((_){
final UserModel userModel=Provider.of<UserModel>(context,listen: false);
if(userModel!=null&&userModel.user!=null){
Future.delayed(Duration(milliseconds: 50),(){
_sellerCodeController.text=userModel.user.sellercode;
_accountController.text=userModel.user.account;
FocusScope.of(context).requestFocus(_pwdFocusNode);
});
}
});
}
handlePostFrame(_){
_scrollController.jumpTo(_scrollController.position.maxScrollExtent);
}
@override
void didChangeMetrics() {
// TODO: implement didChangeMetrics
WidgetsBinding.instance.addPostFrameCallback(handlePostFrame);
super.didChangeDependencies();
}
@override
void dispose() {
// TODO: implement dispose
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
//监听输入框,设置登录按钮状态
setActivate(){
if(_sellerCodeController.text.isNotEmpty&&_accountController.text.isNotEmpty&&_pwdController.text.isNotEmpty){
setState(() {
errorText="";
isActivate=true;
});
}else{
setState(() {
errorText="";
isActivate=false;
});
}
}
//判断是否登录
void isLogin()async{
await App.initSp();
UserModel userModel=Provider.of<UserModel>(context,listen: false);
userModel.initUser();
if(App.sp.getBool("isLogin")??false){
Future.delayed(Duration(milliseconds: 200),(){
NavigatorUtil.goHomePage(context);
});
}
}
@override
Widget build(BuildContext context) {
// TODO: implement build
ScreenUtil.init(context,width: 750,height: 1334);
final Size size=MediaQuery.of(context).size;
App.screenWidth=size.width;
App.screenHeight=size.height;
App.statusBarHeight=MediaQuery.of(context).padding.top;
App.bottomBarHeight=MediaQuery.of(context).padding.bottom;
final double prefixIconWidth=ScreenUtil().setWidth(24);
return Scaffold(
backgroundColor: MyColours.color_ffffff,
body: Container(
width: double.infinity,
height: double.infinity,
child: SingleChildScrollView(
controller: _scrollController,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
VEmptyView(218-App.statusBarHeight),
Image.asset("assets/logo.png",width: ScreenUtil().setWidth(217),height: ScreenUtil().setWidth(206),),
VEmptyView(121),
Container(
height: ScreenUtil().setHeight(84),
width: ScreenUtil().setWidth(611),
padding: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: MyColours.color_bff6f7,width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(8))
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset("assets/icon_sellercode.png",width: prefixIconWidth,),
HEmptyView(26),
Text("商户编号",style: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(28)),),
Expanded(
child: TextField(
controller: _sellerCodeController,
focusNode: _sellerCodeFocusNode,
autofocus: _sellerCodeController.text.isEmpty,
style: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(28),textBaseline: TextBaseline.alphabetic),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
hintText: "请输入6位商户编码",
hintStyle: TextStyle(color: MyColours.color_c1c1c1,fontSize: ScreenUtil().setSp(28),),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 14),
),
onChanged: (_){
setActivate();
},
keyboardType: TextInputType.number,
),
)
],
)
),
Container(
height: ScreenUtil().setHeight(84),
width: ScreenUtil().setWidth(611),
padding: EdgeInsets.only(left: ScreenUtil().setWidth(20)),
margin: EdgeInsets.only(top: ScreenUtil().setHeight(8)),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: MyColours.color_bff6f7,width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(8))
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset("assets/icon_account.png",width: prefixIconWidth,),
HEmptyView(26),
Text("工 号",style: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(28)),),
Expanded(
child: TextField(
controller: _accountController,
focusNode: _accountFocusNode,
style: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(28)),
decoration: InputDecoration(
hintText: "请输入4位工号",
hintStyle: TextStyle(color: MyColours.color_c1c1c1,fontSize: ScreenUtil().setSp(28)),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 14),
),
onChanged: (_){
setActivate();
},
keyboardType: TextInputType.number,
),
)
],
)
),
Container(
height: ScreenUtil().setHeight(84),
width: ScreenUtil().setWidth(611),
padding: EdgeInsets.only(left: ScreenUtil().setWidth(20),right: ScreenUtil().setWidth(27)),
margin: EdgeInsets.only(top: ScreenUtil().setHeight(8)),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: MyColours.color_bff6f7,width: ScreenUtil().setWidth(2)),
borderRadius: BorderRadius.circular(ScreenUtil().setWidth(8))
),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Image.asset("assets/icon_pwd.png",width: prefixIconWidth,),
HEmptyView(26),
Text("密 码",style: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(28)),),
Expanded(
child: TextField(
controller: _pwdController,
focusNode: _pwdFocusNode,
autofocus: _sellerCodeController.text.isNotEmpty&&_accountController.text.isNotEmpty&&_pwdController.text.isEmpty,
style: TextStyle(color: MyColours.color_353535,fontSize: ScreenUtil().setSp(28)),
decoration: InputDecoration(
hintText: "请输入密码",
hintStyle: TextStyle(color: MyColours.color_c1c1c1,fontSize: ScreenUtil().setSp(28)),
border: InputBorder.none,
contentPadding: EdgeInsets.symmetric(horizontal: 10,vertical: 14),
),
onChanged: (_){
setActivate();
},
obscureText: obscureText,
keyboardType: TextInputType.text,
),
),
GestureDetector(
child: Padding(padding: EdgeInsets.all(ScreenUtil().setWidth(10)),child: Image.asset(obscureText?"assets/icon_pwd_show.png":"assets/icon_pwd_hide.png",width: ScreenUtil().setWidth(35),height: ScreenUtil().setHeight(24),),),
onTap: (){
setState(() {
obscureText=!obscureText;
});
},
)
],
)
),
Container(
width: ScreenUtil().setWidth(611),
margin: EdgeInsets.only(top: ScreenUtil().setHeight(16)),
alignment: Alignment.centerLeft,
child: Text(errorText,style: TextStyle(color: MyColours.color_d93535,fontSize: ScreenUtil().setSp(16)),),
),
Consumer<UserModel>(
builder: (BuildContext context,UserModel value,Widget child){
return GestureDetector(
onTap: (){
if(!isActivate)return;
Map<String,String> params={
"seller_code":"${_sellerCodeController.text}",
"alias":"ssahdahgdafgahjkhakjgh",
"account":"${_accountController.text}",
"password":"${_pwdController.text}"
};
value.login(context, params).then((value){
setState(() {
errorText=value??"";
});
});
},
child: Container(
height: ScreenUtil().setHeight(80),
width: ScreenUtil().setWidth(611),
margin: EdgeInsets.only(top: ScreenUtil().setHeight(56)),
alignment: Alignment.center,
decoration: BoxDecoration(
color: isActivate?MyColours.color_2bb5b7:MyColours.color_2bb5b7,
boxShadow: [
BoxShadow(color: MyColours.color_26000000,offset: Offset(0,ScreenUtil().setWidth(4)),)
],
borderRadius: BorderRadius.all(Radius.circular(ScreenUtil().setWidth(8)))
),
child: Text("登录",style: TextStyle(color: MyColours.color_ffffff,fontSize: ScreenUtil().setSp(34)),),
),
);
},
),
VEmptyView(20),
Row(
// mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
InkWell(
onTap: () {
setState(() {
_check = !_check;
});
},
child: Container(
// color: Colors.red,
// height: ScreenUtil().setWidth(34),
padding: EdgeInsets.only(
left: ScreenUtil().setWidth(102),
top: ScreenUtil().setWidth(10),
bottom: ScreenUtil().setWidth(10)),
child: Center(
child: Image.asset(
_check
? "assets/mine_radio_sel.png"
: "assets/mine_radio_nor.png",
width: ScreenUtil().setWidth(42),
height: ScreenUtil().setWidth(42)),
))),
HEmptyView(6),
Text(
'已阅读并同意',
style: TextStyle(
fontSize: ScreenUtil().setSp(24),
color: MyColours.color_353535),
),
InkWell(
onTap: () {
NavigatorUtil.goWebPage(context, '软件服务协议', "xy");
},
child: Text(
'《软件服务协议》',
style: TextStyle(
fontSize: ScreenUtil().setSp(24),
color: MyColours.color_2bb5b7),
),
),
Text('及',
style: TextStyle(
fontSize: ScreenUtil().setSp(24),
color: MyColours.color_353535)),
InkWell(
onTap: () {
NavigatorUtil.goWebPage(context, '隐私政策', "zc");
},
child: Text('《隐私政策》',
style: TextStyle(
fontSize: ScreenUtil().setSp(24),
color: MyColours.color_2bb5b7)),
)
],
),
],
),
),
)
);
}
}