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