|
@@ -0,0 +1,260 @@
|
|
1
|
+import 'package:flutter/material.dart';
|
|
2
|
+import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
3
|
+import 'package:fluttertoast/fluttertoast.dart';
|
|
4
|
+import 'package:get/get.dart';
|
|
5
|
+import 'package:worker_client/models/app.dart';
|
|
6
|
+import 'package:worker_client/models/entities/person.dart';
|
|
7
|
+import 'package:worker_client/services/user.dart';
|
|
8
|
+import 'package:worker_client/widgets/MyButton/index.dart';
|
|
9
|
+import 'package:worker_client/widgets/layout/BasicPage.dart';
|
|
10
|
+
|
|
11
|
+class UserInfo extends BasicPage {
|
|
12
|
+ UserInfo({Key? key}) : super(key: key);
|
|
13
|
+
|
|
14
|
+ AppController store = AppController.t;
|
|
15
|
+ late String name;
|
|
16
|
+ late String phone;
|
|
17
|
+ late TextEditingController _cName;
|
|
18
|
+ late TextEditingController _cPhone;
|
|
19
|
+
|
|
20
|
+ @override
|
|
21
|
+ void beforeShow() {
|
|
22
|
+ // TODO: implement beforeShow
|
|
23
|
+ super.beforeShow();
|
|
24
|
+ _cName = TextEditingController(text: store.user().nickName.toString());
|
|
25
|
+ _cPhone = TextEditingController(text: store.user().phone.toString());
|
|
26
|
+ name = store.user().nickName.toString();
|
|
27
|
+ phone = store.user().phone.toString();
|
|
28
|
+ }
|
|
29
|
+ RegExp exp = RegExp(r'^1[3456789]\d{9}$');
|
|
30
|
+
|
|
31
|
+ void handleOk() {
|
|
32
|
+ if (name == '' && phone == '') {
|
|
33
|
+ Fluttertoast.showToast(msg: '请输入您需要修改的信息');
|
|
34
|
+ return;
|
|
35
|
+ } else if (phone != '' && !exp.hasMatch(phone)) {
|
|
36
|
+ Fluttertoast.showToast(msg: '请输入正确的手机号');
|
|
37
|
+ return;
|
|
38
|
+ } else {
|
|
39
|
+ updateInfo(store.user().personId.toString(), {
|
|
40
|
+ ...store.user().toJson(),
|
|
41
|
+ 'nickName': name,
|
|
42
|
+ 'phone': phone
|
|
43
|
+ }).then((value) {
|
|
44
|
+ Fluttertoast.showToast(msg: '修改成功');
|
|
45
|
+ store.user(Person.fromJson(value));
|
|
46
|
+ Get.offNamed('/main');
|
|
47
|
+ });
|
|
48
|
+ }
|
|
49
|
+ }
|
|
50
|
+
|
|
51
|
+ @override
|
|
52
|
+ Widget builder(BuildContext context) {
|
|
53
|
+ naviTitle = '个人信息';
|
|
54
|
+ return Container(
|
|
55
|
+ padding: EdgeInsets.all(15.w),
|
|
56
|
+ decoration: const BoxDecoration(color: Colors.white),
|
|
57
|
+ child: Column(
|
|
58
|
+ children: [
|
|
59
|
+ Container(
|
|
60
|
+ width: 345.w,
|
|
61
|
+ height: 92.h,
|
|
62
|
+ alignment: Alignment.centerLeft,
|
|
63
|
+ decoration: BoxDecoration(color: Colors.white, boxShadow: [
|
|
64
|
+ BoxShadow(color: Color(0x1f000000), offset: Offset(0, 1.w))
|
|
65
|
+ ]),
|
|
66
|
+ child: store.user().avatar != null
|
|
67
|
+ ? Container(
|
|
68
|
+ clipBehavior: Clip.hardEdge,
|
|
69
|
+ decoration: BoxDecoration(
|
|
70
|
+ borderRadius: BorderRadius.all(Radius.circular(31.w))),
|
|
71
|
+ child: Image.network(
|
|
72
|
+ store.user().avatar.toString(),
|
|
73
|
+ width: 62.w,
|
|
74
|
+ height: 62.w,
|
|
75
|
+ ),
|
|
76
|
+ )
|
|
77
|
+ : Image.asset(
|
|
78
|
+ 'images/main/defaultAvatar.png',
|
|
79
|
+ width: 62.w,
|
|
80
|
+ height: 62.w,
|
|
81
|
+ ),
|
|
82
|
+ ),
|
|
83
|
+ Container(
|
|
84
|
+ width: 345.w,
|
|
85
|
+ alignment: Alignment.centerLeft,
|
|
86
|
+ margin: EdgeInsets.only(top: 40.h),
|
|
87
|
+ decoration: BoxDecoration(color: Colors.white, boxShadow: [
|
|
88
|
+ BoxShadow(color: Color(0x1f000000), offset: Offset(0, 1.w))
|
|
89
|
+ ]),
|
|
90
|
+ child: Column(
|
|
91
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
92
|
+ children: [
|
|
93
|
+ Text(
|
|
94
|
+ '用户名:',
|
|
95
|
+ style: TextStyle(
|
|
96
|
+ color: const Color(0xFF333333),
|
|
97
|
+ letterSpacing: 2,
|
|
98
|
+ fontSize: 17.sp,
|
|
99
|
+ fontWeight: FontWeight.bold),
|
|
100
|
+ ),
|
|
101
|
+ Container(
|
|
102
|
+ height: 54.h,
|
|
103
|
+ alignment: Alignment.centerLeft,
|
|
104
|
+ child: store.user().userName != null
|
|
105
|
+ ? Text(
|
|
106
|
+ store.user().userName.toString(),
|
|
107
|
+ style: TextStyle(
|
|
108
|
+ color: const Color(0xFF333333),
|
|
109
|
+ fontSize: 17.sp,
|
|
110
|
+ fontWeight: FontWeight.bold),
|
|
111
|
+ )
|
|
112
|
+ : const Text(''),
|
|
113
|
+ ),
|
|
114
|
+ ],
|
|
115
|
+ )),
|
|
116
|
+ Container(
|
|
117
|
+ width: 345.w,
|
|
118
|
+ alignment: Alignment.centerLeft,
|
|
119
|
+ margin: EdgeInsets.only(top: 40.h),
|
|
120
|
+ decoration: BoxDecoration(color: Colors.white, boxShadow: [
|
|
121
|
+ BoxShadow(color: const Color(0x1f000000), offset: Offset(0, 1.w))
|
|
122
|
+ ]),
|
|
123
|
+ child: Column(
|
|
124
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
125
|
+ children: [
|
|
126
|
+ Text(
|
|
127
|
+ '姓名:',
|
|
128
|
+ style: TextStyle(
|
|
129
|
+ color: const Color(0xFF333333),
|
|
130
|
+ fontSize: 17.sp,
|
|
131
|
+ fontWeight: FontWeight.bold,
|
|
132
|
+ letterSpacing: 2),
|
|
133
|
+ ),
|
|
134
|
+ Container(
|
|
135
|
+ height: 54.h,
|
|
136
|
+ alignment: Alignment.centerLeft,
|
|
137
|
+ child: Row(
|
|
138
|
+ children: [
|
|
139
|
+ Expanded(
|
|
140
|
+ flex: 1,
|
|
141
|
+ child: TextField(
|
|
142
|
+ controller: _cName,
|
|
143
|
+ style: TextStyle(
|
|
144
|
+ fontSize: 17.sp,
|
|
145
|
+ fontWeight: FontWeight.bold,
|
|
146
|
+ color: const Color(0xff333333)),
|
|
147
|
+ decoration: const InputDecoration(
|
|
148
|
+ isCollapsed: true,
|
|
149
|
+ hintText: '请输入您的姓名',
|
|
150
|
+ counterText: '', //去掉右下角的东西
|
|
151
|
+ border: InputBorder.none,
|
|
152
|
+ floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
153
|
+ ),
|
|
154
|
+ onChanged: (val) {
|
|
155
|
+ name = val;
|
|
156
|
+ },
|
|
157
|
+ ),
|
|
158
|
+ ),
|
|
159
|
+ GestureDetector(
|
|
160
|
+ behavior: HitTestBehavior.opaque,
|
|
161
|
+ onTap: () {
|
|
162
|
+ name = '';
|
|
163
|
+ _cName.clear();
|
|
164
|
+ },
|
|
165
|
+ child: Container(
|
|
166
|
+ width: 50.w,
|
|
167
|
+ alignment: Alignment.center,
|
|
168
|
+ child: Image.asset(
|
|
169
|
+ 'images/main/cancel.png',
|
|
170
|
+ width: 18.w,
|
|
171
|
+ ),
|
|
172
|
+ ),
|
|
173
|
+ )
|
|
174
|
+ ],
|
|
175
|
+ ),
|
|
176
|
+ ),
|
|
177
|
+ ],
|
|
178
|
+ ),
|
|
179
|
+ ),
|
|
180
|
+ Container(
|
|
181
|
+ width: 345.w,
|
|
182
|
+ alignment: Alignment.centerLeft,
|
|
183
|
+ margin: EdgeInsets.only(top: 40.h),
|
|
184
|
+ decoration: BoxDecoration(color: Colors.white, boxShadow: [
|
|
185
|
+ BoxShadow(color: Color(0x1f000000), offset: Offset(0, 1.w))
|
|
186
|
+ ]),
|
|
187
|
+ child: Column(
|
|
188
|
+ crossAxisAlignment: CrossAxisAlignment.start,
|
|
189
|
+ children: [
|
|
190
|
+ Text(
|
|
191
|
+ '手机号:',
|
|
192
|
+ style: TextStyle(
|
|
193
|
+ color: const Color(0xFF333333),
|
|
194
|
+ letterSpacing: 2,
|
|
195
|
+ fontSize: 17.sp,
|
|
196
|
+ fontWeight: FontWeight.bold),
|
|
197
|
+ ),
|
|
198
|
+ Container(
|
|
199
|
+ height: 54.h,
|
|
200
|
+ alignment: Alignment.centerLeft,
|
|
201
|
+ child: Row(
|
|
202
|
+ children: [
|
|
203
|
+ Expanded(
|
|
204
|
+ flex: 1,
|
|
205
|
+ child: TextField(
|
|
206
|
+ //赋初值
|
|
207
|
+ controller: _cPhone,
|
|
208
|
+ maxLength: 11,
|
|
209
|
+ keyboardType: TextInputType.number,
|
|
210
|
+ style: TextStyle(
|
|
211
|
+ fontSize: 17.sp,
|
|
212
|
+ fontWeight: FontWeight.bold,
|
|
213
|
+ color: const Color(0xff333333)),
|
|
214
|
+ decoration: const InputDecoration(
|
|
215
|
+ isCollapsed: true,
|
|
216
|
+ hintText: '请输入您的手机号',
|
|
217
|
+ counterText: '', //去掉右下角的东西
|
|
218
|
+ border: InputBorder.none,
|
|
219
|
+ floatingLabelBehavior: FloatingLabelBehavior.never,
|
|
220
|
+ ),
|
|
221
|
+ onChanged: (val) {
|
|
222
|
+ phone = val;
|
|
223
|
+ },
|
|
224
|
+ ),
|
|
225
|
+ ),
|
|
226
|
+ GestureDetector(
|
|
227
|
+ behavior: HitTestBehavior.opaque,
|
|
228
|
+ onTap: () {
|
|
229
|
+ phone = '';
|
|
230
|
+ _cPhone.clear();
|
|
231
|
+ },
|
|
232
|
+ child: Container(
|
|
233
|
+ width: 50.w,
|
|
234
|
+ alignment: Alignment.center,
|
|
235
|
+ child: Image.asset(
|
|
236
|
+ 'images/main/cancel.png',
|
|
237
|
+ width: 18.w,
|
|
238
|
+ ),
|
|
239
|
+ ),
|
|
240
|
+ ),
|
|
241
|
+ ],
|
|
242
|
+ ),
|
|
243
|
+ ),
|
|
244
|
+ ],
|
|
245
|
+ ),
|
|
246
|
+ ),
|
|
247
|
+ const Spacer(),
|
|
248
|
+ MyButton(
|
|
249
|
+ text: '保存',
|
|
250
|
+ type: 0,
|
|
251
|
+ pwith: 30.w,
|
|
252
|
+ disable: false,
|
|
253
|
+ onClick: () {
|
|
254
|
+ handleOk();
|
|
255
|
+ })
|
|
256
|
+ ],
|
|
257
|
+ ),
|
|
258
|
+ );
|
|
259
|
+ }
|
|
260
|
+}
|