index.dart 9.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269
  1. import 'package:farmer_client/widgets/DefaultButton.dart';
  2. import 'package:farmer_client/widgets/layout/BasicPage.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flutter_easyloading/flutter_easyloading.dart';
  5. import 'package:flutter_screenutil/flutter_screenutil.dart';
  6. import 'package:fluttertoast/fluttertoast.dart';
  7. import 'package:get/get.dart';
  8. import '../../models/app.dart';
  9. import '../../models/entities/person.dart';
  10. import '../../services/user.dart';
  11. class UserInfo extends BasicPage {
  12. late String name;
  13. late String phone;
  14. late TextEditingController _cName;
  15. late TextEditingController _cPhone;
  16. AppController userInfo = AppController.t;
  17. @override
  18. void beforeShow() {
  19. super.beforeShow();
  20. name = userInfo.user().nickName != null
  21. ? userInfo.user().nickName.toString()
  22. : '';
  23. phone = userInfo.user().phone.toString();
  24. _cName = TextEditingController(text: name);
  25. _cPhone = TextEditingController(text: phone);
  26. }
  27. bool disableLogin = false;
  28. RegExp exp = RegExp(r'^1[3456789]\d{9}$');
  29. Map<String, dynamic> data = {};
  30. void handleOk() {
  31. if (name == '' && phone == '') {
  32. Fluttertoast.showToast(msg: '请输入正确的信息');
  33. return;
  34. } else if (phone == '' && !exp.hasMatch(phone)) {
  35. Fluttertoast.showToast(msg: '请输入正确的手机号');
  36. return;
  37. } else {
  38. data = {
  39. ...userInfo.user().toJson(),
  40. 'nickName': name,
  41. 'phone': phone
  42. };
  43. updateInfo(userInfo.user().personId.toString(), data).then((value) {
  44. // 尝试获取一次人员信息
  45. EasyLoading.show(status: '数据加载中...');
  46. getCurrent().then((person) {
  47. EasyLoading.dismiss();
  48. userInfo.user(Person.fromJson(person));
  49. Fluttertoast.showToast(msg: '保存成功');
  50. Get.offAllNamed('/main');
  51. }).catchError((e) {
  52. EasyLoading.dismiss();
  53. EasyLoading.showError('出错啦!');
  54. print(e);
  55. });
  56. });
  57. }
  58. }
  59. @override
  60. Widget builder(BuildContext context) {
  61. naviTitle = '个人信息';
  62. return Container(
  63. height: 700.h,
  64. color: const Color(0xFFffffff),
  65. padding: EdgeInsets.all(15.w),
  66. child: Column(
  67. crossAxisAlignment: CrossAxisAlignment.start,
  68. children: [
  69. Container(
  70. width: 345.w,
  71. margin: EdgeInsets.fromLTRB(0, 0, 0, 40.h),
  72. padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 0),
  73. decoration: BoxDecoration(
  74. color: const Color(0xFFFFFFFF),
  75. boxShadow: [
  76. BoxShadow(
  77. color: const Color(0x1F000000),
  78. offset: Offset(0, 1.w),
  79. blurRadius: 0,
  80. ),
  81. ],
  82. ),
  83. child: Row(
  84. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  85. children: [
  86. Container(
  87. width: 63.w,
  88. height: 63.w,
  89. decoration: BoxDecoration(
  90. shape: BoxShape.circle,
  91. image: userInfo.user().avatar != null
  92. ? DecorationImage(
  93. image: NetworkImage(
  94. userInfo.user().avatar.toString()),
  95. fit: BoxFit.cover,
  96. )
  97. : DecorationImage(
  98. image: AssetImage('images/userMoren.png')),
  99. ),
  100. ),
  101. GestureDetector(
  102. onTap: () {
  103. Get.toNamed("/resetPassword");
  104. },
  105. child: Text("修改密码", style: TextStyle(
  106. color: const Color(0xFF333333),
  107. fontSize: 17.sp,
  108. fontWeight: FontWeight.bold,
  109. letterSpacing: 2),),
  110. )
  111. ]),
  112. ),
  113. Text(
  114. '姓名:',
  115. style: TextStyle(
  116. color: const Color(0xFF333333),
  117. fontSize: 17.sp,
  118. letterSpacing: 2,
  119. fontWeight: FontWeight.bold),
  120. ),
  121. Container(
  122. width: 345.w,
  123. margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
  124. padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
  125. decoration: BoxDecoration(
  126. color: const Color(0xFFFFFFFF),
  127. boxShadow: [
  128. BoxShadow(
  129. color: const Color(0x1F000000),
  130. offset: Offset(0, 1.w),
  131. blurRadius: 0,
  132. ),
  133. ],
  134. ),
  135. child: Column(
  136. children: [
  137. Row(
  138. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  139. children: [
  140. SizedBox(
  141. width: 327.w,
  142. child: TextField(
  143. controller: _cName,
  144. style: TextStyle(
  145. color: const Color(0xFF333333),
  146. fontSize: 17.sp,
  147. letterSpacing: 2,
  148. fontWeight: FontWeight.bold),
  149. decoration: const InputDecoration(
  150. isCollapsed: true,
  151. hintText: '请输入您的姓名',
  152. border: InputBorder.none,
  153. counterText: '', //去掉计数
  154. floatingLabelBehavior:
  155. FloatingLabelBehavior.never,
  156. ),
  157. onChanged: (e) {
  158. name = e;
  159. print(name);
  160. },
  161. ),
  162. ),
  163. GestureDetector(
  164. behavior: HitTestBehavior.opaque,
  165. onTap: () {
  166. name = '';
  167. _cName.clear();
  168. },
  169. child: Image.asset(
  170. 'images/icons/cancel.png',
  171. width: 18.w,
  172. height: 18.w,
  173. ),
  174. ),
  175. ]),
  176. ],
  177. )),
  178. Text(
  179. '手机号:',
  180. style: TextStyle(
  181. color: const Color(0xFF333333),
  182. fontSize: 17.sp,
  183. letterSpacing: 2,
  184. fontWeight: FontWeight.bold),
  185. ),
  186. Container(
  187. width: 345.w,
  188. margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
  189. padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
  190. decoration: BoxDecoration(
  191. color: const Color(0xFFFFFFFF),
  192. boxShadow: [
  193. BoxShadow(
  194. color: const Color(0x1F000000),
  195. offset: Offset(0, 1.w),
  196. blurRadius: 0,
  197. ),
  198. ],
  199. ),
  200. child: Column(
  201. children: [
  202. Row(
  203. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  204. children: [
  205. SizedBox(
  206. width: 327.w,
  207. child: TextField(
  208. keyboardType: TextInputType.number,
  209. controller: _cPhone,
  210. maxLength: 11,
  211. style: TextStyle(
  212. color: const Color(0xFF333333),
  213. fontSize: 17.sp,
  214. letterSpacing: 2,
  215. fontWeight: FontWeight.bold),
  216. decoration: const InputDecoration(
  217. isCollapsed: true,
  218. hintText: '请输入您的手机号',
  219. border: InputBorder.none,
  220. counterText: '', //去掉计数
  221. floatingLabelBehavior:
  222. FloatingLabelBehavior.never,
  223. ),
  224. onChanged: (e) {
  225. phone = e;
  226. },
  227. ),
  228. ),
  229. GestureDetector(
  230. behavior: HitTestBehavior.opaque,
  231. onTap: () {
  232. phone = '';
  233. _cPhone.clear();
  234. },
  235. child: Image.asset(
  236. 'images/icons/cancel.png',
  237. width: 18.w,
  238. height: 18.w,
  239. ),
  240. ),
  241. ]),
  242. ],
  243. )),
  244. const Spacer(),
  245. DefaultButton(
  246. color: const Color(0xffffffff),
  247. backColor: const Color(0xFFFF703B),
  248. width: 345.w,
  249. height: 49.h,
  250. text: '保存',
  251. onPressed: handleOk,
  252. margin: const EdgeInsets.all(0),
  253. fontSize: 20.sp,
  254. radius: 24.5.w,
  255. ),
  256. ],
  257. ),
  258. );
  259. }
  260. }