index.dart 8.7KB

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