registered_page.dart 26 KB

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