registered_page.dart 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/upload_image_bean_entity.dart';
  4. import 'package:bbyyy/https/my_request.dart';
  5. import 'package:bbyyy/my_tools/my_colors.dart';
  6. import 'package:bbyyy/my_tools/my_tools.dart';
  7. import 'package:bbyyy/paegs/login_page/login_page.dart';
  8. import 'package:flutter/cupertino.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter/services.dart';
  11. import 'package:flutter_svg/svg.dart';
  12. import 'package:image_cropper/image_cropper.dart';
  13. import 'package:image_picker/image_picker.dart';
  14. class RegisteredPage extends StatefulWidget {
  15. @override
  16. _RegisteredPageState createState() => _RegisteredPageState();
  17. }
  18. class _RegisteredPageState extends State<RegisteredPage> {
  19. TextEditingController _phoneNum = TextEditingController(text: '');
  20. TextEditingController _nickname = TextEditingController(text: '');
  21. TextEditingController _pw = TextEditingController(text: '');
  22. int focus = -1;
  23. File _image;
  24. final picker = ImagePicker();
  25. @override
  26. Widget build(BuildContext context) {
  27. return GestureDetector(
  28. onTap: () {
  29. MyTools().hideKeyboard(context);
  30. setState(() {
  31. focus = -1;
  32. });
  33. },
  34. child: Scaffold(
  35. body: SingleChildScrollView(
  36. child: Column(
  37. children: [
  38. Column(
  39. children: [
  40. Container(
  41. height: MediaQuery.of(context).size.width * (506 / 750),
  42. child: Stack(
  43. children: [
  44. Image.asset(
  45. 'images/bg_1.png',
  46. width: MediaQuery.of(context).size.width,
  47. height:
  48. MediaQuery.of(context).size.width * (506 / 750),
  49. ),
  50. Positioned(
  51. top: 67,
  52. child: Column(
  53. children: [
  54. Stack(
  55. children: [
  56. Image.asset(
  57. 'images/yuan_bg.png',
  58. height: 147,
  59. width: 147,
  60. ),
  61. GestureDetector(
  62. child: _image == null
  63. ? SvgPicture.asset(
  64. 'images/svg/头像上传.svg',
  65. height: 75,
  66. width: 75,
  67. )
  68. : ClipRRect(
  69. child: Image.file(
  70. _image,
  71. height: 75,
  72. width: 75,
  73. ),
  74. borderRadius: BorderRadius.all(
  75. Radius.circular(75 / 2)),
  76. ),
  77. onTap: () async {
  78. final pickedFile =
  79. await picker.getImage(
  80. source: ImageSource.gallery);
  81. print('pickedFile---${pickedFile.path}');
  82. if (pickedFile != null) {
  83. File cropperImg =
  84. await ImageCropper.cropImage(
  85. sourcePath: pickedFile.path,
  86. aspectRatioPresets: [
  87. CropAspectRatioPreset
  88. .square,
  89. ],
  90. androidUiSettings:
  91. AndroidUiSettings(
  92. toolbarTitle: '图片剪裁',
  93. toolbarColor:
  94. MyColors.cFF4233,
  95. toolbarWidgetColor:
  96. Colors.white,
  97. initAspectRatio:
  98. CropAspectRatioPreset
  99. .square,
  100. lockAspectRatio:
  101. true),
  102. iosUiSettings: IOSUiSettings(
  103. minimumAspectRatio: 1.0,
  104. ));
  105. if (cropperImg != null) {
  106. setState(() {
  107. print('cropperImg---${cropperImg.path}');
  108. _image = cropperImg;
  109. print('_image---${_image.path}');
  110. });
  111. }
  112. }
  113. },
  114. behavior: HitTestBehavior.translucent,
  115. )
  116. ],
  117. alignment: Alignment.center,
  118. ),
  119. Container(
  120. child: Text(
  121. '头像上传',
  122. style: TextStyle(
  123. color: Colors.white, fontSize: 14),
  124. ),
  125. margin: EdgeInsets.only(top: 6),
  126. )
  127. ],
  128. ),
  129. )
  130. ],
  131. alignment: Alignment.topCenter,
  132. ),
  133. ),
  134. Container(
  135. padding: EdgeInsets.only(left: 47, right: 47, top: 26),
  136. child: Column(
  137. children: [
  138. Container(
  139. child: Text(
  140. 'Hello Welcome !',
  141. style: TextStyle(
  142. color: MyColors.cFF4233, fontSize: 24),
  143. ),
  144. margin: EdgeInsets.only(bottom: 25),
  145. ),
  146. Row(
  147. children: [
  148. Container(
  149. child: SvgPicture.asset(
  150. 'images/svg/手机.svg',
  151. height: 22,
  152. width: 22,
  153. ),
  154. height: 22,
  155. width: 22,
  156. ),
  157. Expanded(
  158. child: TextField(
  159. controller: _phoneNum,
  160. inputFormatters: [
  161. onlyInputNumberAndWorkFormatter(),
  162. LengthLimitingTextInputFormatter(11)
  163. ],
  164. cursorColor: MyColors.cFF4233,
  165. cursorWidth: 1.0,
  166. onTap: () {
  167. setState(() {
  168. focus = 0;
  169. });
  170. },
  171. decoration: InputDecoration(
  172. border: InputBorder.none,
  173. disabledBorder: InputBorder.none,
  174. enabledBorder: InputBorder.none,
  175. focusedBorder: InputBorder.none,
  176. isDense: true,
  177. hintText: '请输入手机号',
  178. hintStyle: TextStyle(
  179. color: MyColors.c999999,
  180. fontSize: 16),
  181. contentPadding: const EdgeInsets.fromLTRB(
  182. 14, 4.5, 8, 4.5),
  183. ),
  184. maxLines: 1,
  185. style: TextStyle(
  186. color: MyColors.c333333,
  187. fontSize: 16,
  188. height: 1.3,
  189. letterSpacing: 0.2),
  190. keyboardType: TextInputType.number,
  191. onChanged: (t) {},
  192. ),
  193. )
  194. ],
  195. ),
  196. Container(
  197. height: 1,
  198. color: focus == 0
  199. ? MyColors.cFF4233
  200. : MyColors.cD7D7D7,
  201. margin: EdgeInsets.only(top: 8, bottom: 39),
  202. ),
  203. Row(
  204. children: [
  205. Container(
  206. child: SvgPicture.asset(
  207. 'images/svg/昵称.svg',
  208. height: 22,
  209. width: 22,
  210. ),
  211. height: 22,
  212. width: 22,
  213. ),
  214. Expanded(
  215. child: TextField(
  216. controller: _nickname,
  217. cursorColor: MyColors.cFF4233,
  218. cursorWidth: 1.0,
  219. onTap: () {
  220. setState(() {
  221. focus = 2;
  222. });
  223. },
  224. decoration: InputDecoration(
  225. border: InputBorder.none,
  226. disabledBorder: InputBorder.none,
  227. enabledBorder: InputBorder.none,
  228. focusedBorder: InputBorder.none,
  229. hintText: '请输入昵称',
  230. hintStyle: TextStyle(
  231. color: MyColors.c999999,
  232. fontSize: 16),
  233. isDense: true,
  234. contentPadding:
  235. const EdgeInsets.fromLTRB(
  236. 14, 4.5, 8, 4.5)),
  237. maxLines: 1,
  238. style: TextStyle(
  239. color: MyColors.c333333,
  240. fontSize: 16,
  241. height: 1.3,
  242. letterSpacing: 0.2),
  243. keyboardType: TextInputType.text,
  244. onChanged: (t) {},
  245. ),
  246. ),
  247. ],
  248. ),
  249. // Row(
  250. // children: [
  251. // Container(
  252. // child: SvgPicture.asset(
  253. // 'images/svg/验证码.svg',
  254. // height: 22,
  255. // width: 22,
  256. // ),
  257. // height: 22,
  258. // width: 22,
  259. // ),
  260. // Expanded(
  261. // child: TextField(
  262. // controller: _verificationCode,
  263. // cursorColor: MyColors.cFF4233,
  264. // cursorWidth: 1.0,
  265. // onTap: () {
  266. // setState(() {
  267. // focus = 1;
  268. // });
  269. // },
  270. // decoration: InputDecoration(
  271. // border: InputBorder.none,
  272. // disabledBorder: InputBorder.none,
  273. // enabledBorder: InputBorder.none,
  274. // focusedBorder: InputBorder.none,
  275. // hintText: '请输入验证码',
  276. // hintStyle: TextStyle(
  277. // color: MyColors.c999999, fontSize: 16),
  278. // isDense: true,
  279. // contentPadding:
  280. // const EdgeInsets.fromLTRB(14, 4.5, 8, 4.5)),
  281. // maxLines: 1,
  282. // style: TextStyle(
  283. // color: MyColors.c333333,
  284. // fontSize: 16,
  285. // height: 1.3,
  286. // letterSpacing: 0.2),
  287. // keyboardType: TextInputType.text,
  288. // onChanged: (t) {},
  289. // ),
  290. // ),
  291. // Container(
  292. // decoration: BoxDecoration(
  293. // color: MyColors.c19FF4233,
  294. // borderRadius:
  295. // BorderRadius.all(Radius.circular(4))),
  296. // height: 34,
  297. // width: 90,
  298. // )
  299. // ],
  300. // ),
  301. Container(
  302. height: 1,
  303. color: focus == 2
  304. ? MyColors.cFF4233
  305. : MyColors.cD7D7D7,
  306. margin: EdgeInsets.only(top: 8, bottom: 39),
  307. ),
  308. Row(
  309. children: [
  310. Container(
  311. child: SvgPicture.asset(
  312. 'images/svg/密码.svg',
  313. height: 22,
  314. width: 22,
  315. ),
  316. height: 22,
  317. width: 22,
  318. ),
  319. Expanded(
  320. child: TextField(
  321. controller: _pw,
  322. inputFormatters: [
  323. onlyInputNumberAndWorkFormatter(),
  324. LengthLimitingTextInputFormatter(8)
  325. ],
  326. cursorColor: MyColors.cFF4233,
  327. cursorWidth: 1.0,
  328. onTap: () {
  329. setState(() {
  330. focus = 1;
  331. });
  332. },
  333. decoration: InputDecoration(
  334. border: InputBorder.none,
  335. disabledBorder: InputBorder.none,
  336. enabledBorder: InputBorder.none,
  337. focusedBorder: InputBorder.none,
  338. hintText: '请输入密码(6到8位)',
  339. hintStyle: TextStyle(
  340. color: MyColors.c999999,
  341. fontSize: 16),
  342. isDense: true,
  343. contentPadding:
  344. const EdgeInsets.fromLTRB(
  345. 14, 4.5, 8, 4.5)),
  346. maxLines: 1,
  347. style: TextStyle(
  348. color: MyColors.c333333,
  349. fontSize: 16,
  350. height: 1.3,
  351. letterSpacing: 0.2),
  352. keyboardType: TextInputType.visiblePassword,
  353. obscureText: true,
  354. onChanged: (t) {},
  355. ),
  356. )
  357. ],
  358. ),
  359. Container(
  360. height: 1,
  361. color: focus == 1
  362. ? MyColors.cFF4233
  363. : MyColors.cD7D7D7,
  364. margin: EdgeInsets.only(top: 8, bottom: 39),
  365. ),
  366. GestureDetector(
  367. onTap: () {
  368. if (_phoneNum.text.isEmpty ||
  369. _phoneNum.text.length != 11) {
  370. showToast('请填写正确的手机号');
  371. return;
  372. }
  373. if (_pw.text.isEmpty || _pw.text.length < 6) {
  374. showToast('请填写正确的密码(由数字和字母组合的至少6位的组合)');
  375. return;
  376. }
  377. if (_nickname.text.isEmpty) {
  378. showToast('请填写昵称');
  379. return;
  380. }
  381. if (_image == null) {
  382. showToast('请设置头像');
  383. return;
  384. }
  385. uploadAvatar();
  386. },
  387. behavior: HitTestBehavior.translucent,
  388. child: Container(
  389. decoration: BoxDecoration(
  390. borderRadius: BorderRadius.all(
  391. Radius.circular(20),
  392. ),
  393. gradient: LinearGradient(
  394. colors: MyColors.lg,
  395. ),
  396. ),
  397. height: 44,
  398. child: Text(
  399. '注 册',
  400. style: TextStyle(
  401. color: Colors.white, fontSize: 17),
  402. ),
  403. alignment: Alignment.center,
  404. padding: EdgeInsets.only(bottom: 2),
  405. ),
  406. ),
  407. Container(
  408. alignment: Alignment.centerRight,
  409. child: GestureDetector(
  410. onTap: () {
  411. MyTools().toPage(
  412. context, LoginPage(), (then) {},
  413. noBack: true);
  414. },
  415. behavior: HitTestBehavior.translucent,
  416. child: Container(
  417. child: Text(
  418. '已有账号,去登录',
  419. style: TextStyle(
  420. color: MyColors.cFF4233, fontSize: 13),
  421. ),
  422. padding: EdgeInsets.all(8),
  423. margin: EdgeInsets.only(top: 22),
  424. ),
  425. ),
  426. ),
  427. // Expanded(
  428. // child: SafeArea(
  429. // bottom: true,
  430. // child: Container(
  431. // padding: EdgeInsets.only(bottom: 50),
  432. // alignment: Alignment.bottomCenter,
  433. // child: Row(
  434. // children: [
  435. // GestureDetector(
  436. // onTap: () {
  437. // MyTools().toPage(
  438. // context, LoginPage(), (then) {},
  439. // noBack: true);
  440. // },
  441. // behavior: HitTestBehavior.translucent,
  442. // child: Container(
  443. // padding: EdgeInsets.all(8),
  444. // child: Text(
  445. // '登录账号',
  446. // style: TextStyle(
  447. // color: MyColors.c666666, fontSize: 14),
  448. // ),
  449. // ),
  450. // ),
  451. // Container(
  452. // height: 13,
  453. // width: 2,
  454. // decoration: BoxDecoration(
  455. // borderRadius:
  456. // BorderRadius.all(Radius.circular(1)),
  457. // color: MyColors.cFF4233,
  458. // ),
  459. // margin: EdgeInsets.only(left: 27, right: 27),
  460. // ),
  461. // GestureDetector(
  462. // onTap: () {
  463. // MyTools().toPage(
  464. // context, ForgetPasswordPage(), (then) {},
  465. // noBack: true);
  466. // },
  467. // behavior: HitTestBehavior.translucent,
  468. // child: Container(
  469. // padding: EdgeInsets.all(8),
  470. // child: Text(
  471. // '忘记密码',
  472. // style: TextStyle(
  473. // color: MyColors.c666666, fontSize: 14),
  474. // ),
  475. // ),
  476. // ),
  477. // ],
  478. // mainAxisAlignment: MainAxisAlignment.center,
  479. // ),
  480. // ),
  481. // ),
  482. // )
  483. ],
  484. crossAxisAlignment: CrossAxisAlignment.start,
  485. ),
  486. ),
  487. ],
  488. ),
  489. ],
  490. ),
  491. ),
  492. ),
  493. );
  494. }
  495. void uploadAvatar() {
  496. upload(_image, (r, hasError) {
  497. if (!hasError) {
  498. UploadImageBeanEntity data =
  499. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  500. registered(data);
  501. }
  502. }, (error) {});
  503. }
  504. void registered(UploadImageBeanEntity data) {
  505. registeredAccountNumber({
  506. 'mobile':_phoneNum.text,
  507. 'name':_nickname.text,
  508. 'password':MyTools.base64Encode(_pw.text),
  509. 'picture':data.data[0].path,
  510. }, (re, hasError) {
  511. if(!hasError){
  512. showToast('注册成功');
  513. MyTools().toPage(
  514. context, LoginPage(), (then) {},
  515. noBack: true);
  516. }
  517. }, (error) {});
  518. }
  519. }