index.dart 8.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. import 'package:farmer_client/widgets/DefaultButton.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter_screenutil/flutter_screenutil.dart';
  4. import 'package:fluttertoast/fluttertoast.dart';
  5. import 'package:get/get.dart';
  6. class UserInfo extends StatefulWidget {
  7. const UserInfo({Key? key}) : super(key: key);
  8. @override
  9. _UserInfo createState() => _UserInfo();
  10. }
  11. class _UserInfo extends State<UserInfo> {
  12. String name = '';
  13. String phone = '';
  14. late TextEditingController _cName;
  15. late TextEditingController _cPhone;
  16. @override
  17. void initState() {
  18. _cName = new TextEditingController(text: name);
  19. _cPhone = new TextEditingController(text: phone);
  20. }
  21. bool disableLogin = false;
  22. RegExp exp = RegExp(r'^1[3456789]\d{9}$');
  23. void handleOk() {
  24. if (name == '' && phone == '') {
  25. Fluttertoast.showToast(msg: '请输入您的信息');
  26. } else if (phone!=''&&!exp.hasMatch(phone)) {
  27. Fluttertoast.showToast(msg: '请输入正确的手机号');
  28. } else {
  29. Fluttertoast.showToast(msg: '保存成功');
  30. Get.back();
  31. }
  32. }
  33. @override
  34. Widget build(BuildContext context) {
  35. return Scaffold(
  36. //防止键盘弹起引起页面高度溢出
  37. resizeToAvoidBottomInset: false,
  38. appBar: AppBar(
  39. elevation: 0,
  40. centerTitle: true,
  41. backgroundColor: Colors.white,
  42. title: Text(
  43. '个人信息',
  44. style: TextStyle(
  45. color: Colors.black,
  46. fontSize: 17.sp,
  47. letterSpacing: 2,
  48. fontWeight: FontWeight.bold),
  49. ),
  50. ),
  51. body: Container(
  52. color: const Color(0xFFffffff),
  53. padding: EdgeInsets.all(15.w),
  54. child: Column(
  55. crossAxisAlignment: CrossAxisAlignment.start,
  56. children: [
  57. Container(
  58. margin: EdgeInsets.fromLTRB(0, 0, 0, 40.h),
  59. padding: EdgeInsets.symmetric(vertical: 15.h, horizontal: 0),
  60. decoration: BoxDecoration(
  61. color: const Color(0xFFFFFFFF),
  62. boxShadow: [
  63. BoxShadow(
  64. color: const Color(0x1F000000),
  65. offset: Offset(0, 1.w),
  66. blurRadius: 0,
  67. ),
  68. ],
  69. ),
  70. child: Row(
  71. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  72. children: [
  73. Image.asset(
  74. 'images/userMoren.png',
  75. width: 62.w,
  76. height: 62.w,
  77. ),
  78. Text(
  79. '更换头像',
  80. style: TextStyle(
  81. fontSize: 17.sp,
  82. color: Color(0xFF333333),
  83. letterSpacing: 2,
  84. fontWeight: FontWeight.w500),
  85. ),
  86. ]),
  87. ),
  88. Text(
  89. '姓名:',
  90. style: TextStyle(
  91. color: const Color(0xFF333333),
  92. fontSize: 17.sp,
  93. letterSpacing: 2,
  94. fontWeight: FontWeight.bold),
  95. ),
  96. Container(
  97. margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
  98. padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
  99. decoration: BoxDecoration(
  100. color: const Color(0xFFFFFFFF),
  101. boxShadow: [
  102. BoxShadow(
  103. color: const Color(0x1F000000),
  104. offset: Offset(0, 1.w),
  105. blurRadius: 0,
  106. ),
  107. ],
  108. ),
  109. child: Column(
  110. children: [
  111. Row(
  112. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  113. children: [
  114. Container(
  115. width: 327.w,
  116. child: TextField(
  117. controller: _cName,
  118. style: TextStyle(
  119. color: const Color(0xFF333333),
  120. fontSize: 17.sp,
  121. letterSpacing: 2,
  122. fontWeight: FontWeight.bold),
  123. decoration: const InputDecoration(
  124. isCollapsed: true,
  125. hintText: '请输入您的姓名',
  126. border: InputBorder.none,
  127. counterText: '', //去掉计数
  128. floatingLabelBehavior:
  129. FloatingLabelBehavior.never,
  130. ),
  131. onChanged: (e) {
  132. setState(() {
  133. name = e;
  134. });
  135. },
  136. ),
  137. ),
  138. GestureDetector(
  139. onTap: () {
  140. setState(() {
  141. name = '';
  142. });
  143. _cName.clear();
  144. },
  145. child: Image.asset(
  146. 'images/icons/cancel.png',
  147. width: 18.w,
  148. height: 18.w,
  149. ),
  150. ),
  151. ]),
  152. ],
  153. )),
  154. Text(
  155. '手机号:',
  156. style: TextStyle(
  157. color: const Color(0xFF333333),
  158. fontSize: 17.sp,
  159. letterSpacing: 2,
  160. fontWeight: FontWeight.bold),
  161. ),
  162. Container(
  163. margin: EdgeInsets.fromLTRB(0, 10.h, 0, 40.h),
  164. padding: EdgeInsets.symmetric(vertical: 19.h, horizontal: 0),
  165. decoration: BoxDecoration(
  166. color: const Color(0xFFFFFFFF),
  167. boxShadow: [
  168. BoxShadow(
  169. color: const Color(0x1F000000),
  170. offset: Offset(0, 1.w),
  171. blurRadius: 0,
  172. ),
  173. ],
  174. ),
  175. child: Column(
  176. children: [
  177. Row(
  178. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  179. children: [
  180. SizedBox(
  181. width: 327.w,
  182. child: TextField(
  183. keyboardType: TextInputType.number,
  184. controller: _cPhone,
  185. maxLength: 11,
  186. style: TextStyle(
  187. color: const Color(0xFF333333),
  188. fontSize: 17.sp,
  189. letterSpacing: 2,
  190. fontWeight: FontWeight.bold),
  191. decoration: const InputDecoration(
  192. isCollapsed: true,
  193. hintText: '请输入您的手机号',
  194. border: InputBorder.none,
  195. counterText: '', //去掉计数
  196. floatingLabelBehavior:
  197. FloatingLabelBehavior.never,
  198. ),
  199. onChanged: (e) {
  200. setState(() {
  201. phone = e;
  202. });
  203. },
  204. ),
  205. ),
  206. GestureDetector(
  207. onTap: () {
  208. setState(() {
  209. phone = '';
  210. });
  211. _cPhone.clear();
  212. },
  213. child: Image.asset(
  214. 'images/icons/cancel.png',
  215. width: 18.w,
  216. height: 18.w,
  217. ),
  218. ),
  219. ]),
  220. ],
  221. )),
  222. const Spacer(),
  223. DefaultButton(
  224. color: const Color(0xffffffff),
  225. backColor: const Color(0xFFFF703B),
  226. width: 345.w,
  227. height: 49.h,
  228. text: '保存',
  229. onPressed: handleOk,
  230. margin: const EdgeInsets.all(0),
  231. fontSize: 20.sp,
  232. radius: 24.5.w,
  233. ),
  234. ],
  235. ),
  236. ),
  237. );
  238. }
  239. }