index.dart 9.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259
  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. ]),
  102. ),
  103. Text(
  104. '姓名:',
  105. style: TextStyle(
  106. color: const Color(0xFF333333),
  107. fontSize: 17.sp,
  108. letterSpacing: 2,
  109. fontWeight: FontWeight.bold),
  110. ),
  111. Container(
  112. width: 345.w,
  113. margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
  114. padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
  115. decoration: BoxDecoration(
  116. color: const Color(0xFFFFFFFF),
  117. boxShadow: [
  118. BoxShadow(
  119. color: const Color(0x1F000000),
  120. offset: Offset(0, 1.w),
  121. blurRadius: 0,
  122. ),
  123. ],
  124. ),
  125. child: Column(
  126. children: [
  127. Row(
  128. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  129. children: [
  130. SizedBox(
  131. width: 327.w,
  132. child: TextField(
  133. controller: _cName,
  134. style: TextStyle(
  135. color: const Color(0xFF333333),
  136. fontSize: 17.sp,
  137. letterSpacing: 2,
  138. fontWeight: FontWeight.bold),
  139. decoration: const InputDecoration(
  140. isCollapsed: true,
  141. hintText: '请输入您的姓名',
  142. border: InputBorder.none,
  143. counterText: '', //去掉计数
  144. floatingLabelBehavior:
  145. FloatingLabelBehavior.never,
  146. ),
  147. onChanged: (e) {
  148. name = e;
  149. print(name);
  150. },
  151. ),
  152. ),
  153. GestureDetector(
  154. behavior: HitTestBehavior.opaque,
  155. onTap: () {
  156. name = '';
  157. _cName.clear();
  158. },
  159. child: Image.asset(
  160. 'images/icons/cancel.png',
  161. width: 18.w,
  162. height: 18.w,
  163. ),
  164. ),
  165. ]),
  166. ],
  167. )),
  168. Text(
  169. '手机号:',
  170. style: TextStyle(
  171. color: const Color(0xFF333333),
  172. fontSize: 17.sp,
  173. letterSpacing: 2,
  174. fontWeight: FontWeight.bold),
  175. ),
  176. Container(
  177. width: 345.w,
  178. margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
  179. padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
  180. decoration: BoxDecoration(
  181. color: const Color(0xFFFFFFFF),
  182. boxShadow: [
  183. BoxShadow(
  184. color: const Color(0x1F000000),
  185. offset: Offset(0, 1.w),
  186. blurRadius: 0,
  187. ),
  188. ],
  189. ),
  190. child: Column(
  191. children: [
  192. Row(
  193. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  194. children: [
  195. SizedBox(
  196. width: 327.w,
  197. child: TextField(
  198. keyboardType: TextInputType.number,
  199. controller: _cPhone,
  200. maxLength: 11,
  201. style: TextStyle(
  202. color: const Color(0xFF333333),
  203. fontSize: 17.sp,
  204. letterSpacing: 2,
  205. fontWeight: FontWeight.bold),
  206. decoration: const InputDecoration(
  207. isCollapsed: true,
  208. hintText: '请输入您的手机号',
  209. border: InputBorder.none,
  210. counterText: '', //去掉计数
  211. floatingLabelBehavior:
  212. FloatingLabelBehavior.never,
  213. ),
  214. onChanged: (e) {
  215. phone = e;
  216. },
  217. ),
  218. ),
  219. GestureDetector(
  220. behavior: HitTestBehavior.opaque,
  221. onTap: () {
  222. phone = '';
  223. _cPhone.clear();
  224. },
  225. child: Image.asset(
  226. 'images/icons/cancel.png',
  227. width: 18.w,
  228. height: 18.w,
  229. ),
  230. ),
  231. ]),
  232. ],
  233. )),
  234. const Spacer(),
  235. DefaultButton(
  236. color: const Color(0xffffffff),
  237. backColor: const Color(0xFFFF703B),
  238. width: 345.w,
  239. height: 49.h,
  240. text: '保存',
  241. onPressed: handleOk,
  242. margin: const EdgeInsets.all(0),
  243. fontSize: 20.sp,
  244. radius: 24.5.w,
  245. ),
  246. ],
  247. ),
  248. );
  249. }
  250. }