index.dart 9.1KB

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