registered_page.dart 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590
  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/my_tools/protocol.dart';
  12. import 'package:bbyyy/paegs/login_page/login_page.dart';
  13. import 'package:bbyyy/paegs/root_page/root_page.dart';
  14. import 'package:flutter/cupertino.dart';
  15. import 'package:flutter/gestures.dart';
  16. import 'package:flutter/material.dart';
  17. import 'package:flutter/services.dart';
  18. import 'package:flutter_svg/svg.dart';
  19. import 'package:image_cropper/image_cropper.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. bool showPW = true;
  30. int focus = -1;
  31. bool haveRead = false;
  32. File _image;
  33. final picker = ImagePicker();
  34. @override
  35. Widget build(BuildContext context) {
  36. return GestureDetector(
  37. onTap: () {
  38. MyTools().hideKeyboard(context);
  39. setState(() {
  40. focus = -1;
  41. });
  42. },
  43. child: Scaffold(
  44. body: SingleChildScrollView(
  45. child: Column(
  46. children: [
  47. Column(
  48. children: [
  49. Container(
  50. height: MediaQuery.of(context).size.width * (506 / 750),
  51. child: Stack(
  52. children: [
  53. Image.asset(
  54. 'images/bg_1.png',
  55. width: MediaQuery.of(context).size.width,
  56. height:
  57. MediaQuery.of(context).size.width * (506 / 750),
  58. ),
  59. Positioned(
  60. top: 67,
  61. child: Column(
  62. children: [
  63. Stack(
  64. children: [
  65. Image.asset(
  66. 'images/yuan_bg.png',
  67. height: 147,
  68. width: 147,
  69. ),
  70. GestureDetector(
  71. child: _image == null
  72. ? SvgPicture.asset(
  73. 'images/svg/头像上传.svg',
  74. height: 75,
  75. width: 75,
  76. )
  77. : ClipRRect(
  78. child: Image.file(
  79. _image,
  80. height: 75,
  81. width: 75,
  82. ),
  83. borderRadius: BorderRadius.all(
  84. Radius.circular(75 / 2)),
  85. ),
  86. onTap: () async {
  87. final pickedFile = 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(
  96. ratioX: 1, ratioY: 1),
  97. aspectRatioPresets: [
  98. CropAspectRatioPreset.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: true),
  111. iosUiSettings: IOSUiSettings(
  112. minimumAspectRatio: 1.0,
  113. resetAspectRatioEnabled:
  114. false,
  115. rotateButtonsHidden: true));
  116. if (cropperImg != null) {
  117. setState(() {
  118. print(
  119. '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, fontSize: 16),
  192. contentPadding: const EdgeInsets.fromLTRB(
  193. 14, 4.5, 8, 4.5),
  194. ),
  195. maxLines: 1,
  196. style: TextStyle(
  197. color: MyColors.c333333,
  198. fontSize: 16,
  199. height: 1.3,
  200. letterSpacing: 0.2),
  201. keyboardType: TextInputType.number,
  202. onChanged: (t) {},
  203. ),
  204. )
  205. ],
  206. ),
  207. Container(
  208. height: 1,
  209. color:
  210. focus == 0 ? MyColors.cFF4233 : MyColors.cD7D7D7,
  211. margin: EdgeInsets.only(top: 8, bottom: 39),
  212. ),
  213. Row(
  214. children: [
  215. Container(
  216. child: SvgPicture.asset(
  217. 'images/svg/昵称.svg',
  218. height: 22,
  219. width: 22,
  220. ),
  221. height: 22,
  222. width: 22,
  223. ),
  224. Expanded(
  225. child: TextField(
  226. inputFormatters: [
  227. LengthLimitingTextInputFormatter(12)
  228. ],
  229. controller: _nickname,
  230. cursorColor: MyColors.cFF4233,
  231. cursorWidth: 1.0,
  232. onTap: () {
  233. setState(() {
  234. focus = 2;
  235. });
  236. },
  237. decoration: InputDecoration(
  238. border: InputBorder.none,
  239. disabledBorder: InputBorder.none,
  240. enabledBorder: InputBorder.none,
  241. focusedBorder: InputBorder.none,
  242. hintText: '请输入昵称',
  243. hintStyle: TextStyle(
  244. color: MyColors.c999999, fontSize: 16),
  245. isDense: true,
  246. contentPadding: 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:
  315. focus == 2 ? MyColors.cFF4233 : MyColors.cD7D7D7,
  316. margin: EdgeInsets.only(top: 8, bottom: 39),
  317. ),
  318. Row(
  319. children: [
  320. Container(
  321. child: SvgPicture.asset(
  322. 'images/svg/密码.svg',
  323. height: 22,
  324. width: 22,
  325. ),
  326. height: 22,
  327. width: 22,
  328. ),
  329. Expanded(
  330. child: TextField(
  331. controller: _pw,
  332. inputFormatters: [
  333. onlyInputNumberAndWorkFormatter(),
  334. LengthLimitingTextInputFormatter(8)
  335. ],
  336. cursorColor: MyColors.cFF4233,
  337. cursorWidth: 1.0,
  338. onTap: () {
  339. setState(() {
  340. focus = 1;
  341. });
  342. },
  343. decoration: InputDecoration(
  344. border: InputBorder.none,
  345. disabledBorder: InputBorder.none,
  346. enabledBorder: InputBorder.none,
  347. focusedBorder: InputBorder.none,
  348. hintText: '请输入密码(6到8位)',
  349. hintStyle: TextStyle(
  350. color: MyColors.c999999, fontSize: 16),
  351. isDense: true,
  352. contentPadding: const EdgeInsets.fromLTRB(
  353. 14, 4.5, 8, 4.5)),
  354. maxLines: 1,
  355. style: TextStyle(
  356. color: MyColors.c333333,
  357. fontSize: 16,
  358. height: 1.3,
  359. letterSpacing: 0.2),
  360. keyboardType: TextInputType.visiblePassword,
  361. obscureText: !showPW,
  362. onChanged: (t) {},
  363. ),
  364. ),
  365. GestureDetector(
  366. onTap: () {
  367. setState(() {
  368. showPW = !showPW;
  369. });
  370. },
  371. behavior: HitTestBehavior.translucent,
  372. child: Container(
  373. height: 30,width: 30,
  374. padding: EdgeInsets.all(4),
  375. child: SvgPicture.asset(showPW
  376. ? 'images/svg/不显示.svg'
  377. : 'images/svg/显示.svg'))),
  378. ],
  379. ),
  380. Container(
  381. height: 1,
  382. color:
  383. focus == 1 ? MyColors.cFF4233 : MyColors.cD7D7D7,
  384. margin: EdgeInsets.only(top: 8, bottom: 20),
  385. ),
  386. Row(
  387. children: [
  388. Checkbox(
  389. value: haveRead,
  390. onChanged: (v) {
  391. setState(() {
  392. haveRead = v;
  393. });
  394. },
  395. activeColor: MyColors.cFF4233,
  396. ),
  397. RichText(
  398. text: TextSpan(
  399. text: '我已阅读并同意',
  400. style: TextStyle(
  401. color: MyColors.c999999, fontSize: 12),
  402. children: [
  403. TextSpan(
  404. text: '《使用协议》',
  405. style: TextStyle(
  406. color: MyColors.cFF4233,
  407. fontSize: 12),
  408. recognizer: TapGestureRecognizer()
  409. ..onTap = () {
  410. MyTools().toPage(
  411. context,
  412. PrivacyPolicyPage('使用协议'),
  413. (then) {});
  414. }),
  415. TextSpan(
  416. text: '和',
  417. style: TextStyle(
  418. color: MyColors.c999999,
  419. fontSize: 12),
  420. ),
  421. TextSpan(
  422. text: '《隐私政策》',
  423. style: TextStyle(
  424. color: MyColors.cFF4233,
  425. fontSize: 12),
  426. recognizer: TapGestureRecognizer()
  427. ..onTap = () {
  428. MyTools().toPage(
  429. context,
  430. PrivacyPolicyPage('隐私政策'),
  431. (then) {});
  432. }),
  433. ]),
  434. ),
  435. ],
  436. mainAxisAlignment: MainAxisAlignment.end,
  437. ),
  438. GestureDetector(
  439. onTap: () {
  440. if (_phoneNum.text.isEmpty ||
  441. _phoneNum.text.length != 11) {
  442. showToast('请填写正确的手机号');
  443. return;
  444. }
  445. if (_pw.text.isEmpty || _pw.text.length < 6) {
  446. showToast('请填写正确的密码(由数字和字母组合的至少6位的组合)');
  447. return;
  448. }
  449. if (_nickname.text.isEmpty) {
  450. showToast('请填写昵称');
  451. return;
  452. }
  453. if (_image == null) {
  454. showToast('请设置头像');
  455. return;
  456. }
  457. if (!haveRead) {
  458. showToast('请阅读并同意《隐私政策》');
  459. return;
  460. }
  461. uploadAvatar();
  462. },
  463. behavior: HitTestBehavior.translucent,
  464. child: Container(
  465. margin: EdgeInsets.only(top: 20),
  466. decoration: BoxDecoration(
  467. borderRadius: BorderRadius.all(
  468. Radius.circular(20),
  469. ),
  470. gradient: LinearGradient(
  471. colors: MyColors.lg,
  472. ),
  473. ),
  474. height: 44,
  475. child: Text(
  476. '注 册',
  477. style:
  478. TextStyle(color: Colors.white, fontSize: 17),
  479. ),
  480. alignment: Alignment.center,
  481. padding: EdgeInsets.only(bottom: 2),
  482. ),
  483. ),
  484. Container(
  485. alignment: Alignment.centerRight,
  486. child: GestureDetector(
  487. onTap: () {
  488. MyTools().toPage(context, LoginPage(), (then) {},
  489. noBack: true);
  490. },
  491. behavior: HitTestBehavior.translucent,
  492. child: Container(
  493. child: Text(
  494. '已有账号,去登录',
  495. style: TextStyle(
  496. color: MyColors.cFF4233, fontSize: 13),
  497. ),
  498. padding: EdgeInsets.all(8),
  499. margin: EdgeInsets.only(top: 20),
  500. ),
  501. ),
  502. ),
  503. ],
  504. crossAxisAlignment: CrossAxisAlignment.start,
  505. ),
  506. ),
  507. ],
  508. ),
  509. ],
  510. ),
  511. ),
  512. ),
  513. );
  514. }
  515. void uploadAvatar() {
  516. upload(_image, (r, hasError) {
  517. if (!hasError) {
  518. UploadImageBeanEntity data =
  519. UploadImageBeanEntity().fromJson(json.decode(r.data.toString()));
  520. registered(data);
  521. }
  522. }, (error) {});
  523. }
  524. void registered(UploadImageBeanEntity data) {
  525. registeredAccountNumber({
  526. 'mobile': _phoneNum.text,
  527. 'name': _nickname.text,
  528. 'password': MyTools.base64Encode(_pw.text),
  529. 'picture': data.data[0].path,
  530. }, (re, hasError) {
  531. if (!hasError) {
  532. // showToast('注册成功');
  533. // MyTools().toPage(
  534. // context, LoginPage(), (then) {},
  535. // noBack: true);
  536. loginAccount({
  537. 'user': _phoneNum.text,
  538. 'password': MyTools.base64Encode(_pw.text),
  539. 'version': MyCookie().packageInfo.version,
  540. 'phone': Platform.isAndroid ? 'Android' : 'IOS'
  541. }, (r, hE) {
  542. if (!hE) {
  543. LoginInformationBeanEntity entity = LoginInformationBeanEntity()
  544. .fromJson(json.decode(r.data.toString()));
  545. MyCookie().saveLoginInformationBeanEntity(entity);
  546. MyDio().initDio();
  547. MyTools().toPage(context, RootPage(), (then) {}, noBack: true);
  548. }
  549. }, (e) {});
  550. }
  551. }, (error) {});
  552. }
  553. }
  554. class PrivacyPolicyPage extends StatefulWidget {
  555. String type;
  556. PrivacyPolicyPage(this.type);
  557. @override
  558. _PrivacyPolicyPageState createState() => _PrivacyPolicyPageState();
  559. }
  560. class _PrivacyPolicyPageState extends State<PrivacyPolicyPage> {
  561. @override
  562. Widget build(BuildContext context) {
  563. return Scaffold(
  564. body: Column(
  565. children: [
  566. MyViews().myAppBar(widget.type, context, []),
  567. Expanded(
  568. child: SingleChildScrollView(
  569. child: Padding(
  570. padding: const EdgeInsets.all(8.0),
  571. child: Text(
  572. widget.type == '使用协议' ? serviceAgreement : privacyPolicy),
  573. ),
  574. ))
  575. ],
  576. ),
  577. );
  578. }
  579. }