registered_page.dart 25 KB

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