login_page.dart 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/app_store_review_bean_entity.dart';
  4. import 'package:bbyyy/beans/login_information_bean_entity.dart';
  5. import 'package:bbyyy/https/MyDio.dart';
  6. import 'package:bbyyy/https/my_request.dart';
  7. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  8. import 'package:bbyyy/my_tools/event_bus.dart';
  9. import 'package:bbyyy/my_tools/my_apis.dart';
  10. import 'package:bbyyy/my_tools/my_colors.dart';
  11. import 'package:bbyyy/my_tools/my_cookie.dart';
  12. import 'package:bbyyy/my_tools/my_tools.dart';
  13. import 'package:bbyyy/my_tools/my_views.dart';
  14. import 'package:bbyyy/my_tools/protocol.dart';
  15. import 'package:bbyyy/paegs/forget_password_page/forget_password_page.dart';
  16. import 'package:bbyyy/paegs/guest_login_page/root_page.dart';
  17. import 'package:bbyyy/paegs/registered_page/registered_page.dart';
  18. import 'package:bbyyy/paegs/root_page/root_page.dart';
  19. import 'package:flutter/cupertino.dart';
  20. import 'package:flutter/gestures.dart';
  21. import 'package:flutter/material.dart';
  22. import 'package:flutter/services.dart';
  23. import 'package:flutter_svg/flutter_svg.dart';
  24. class LoginPage extends StatefulWidget {
  25. @override
  26. _LoginPageState createState() => _LoginPageState();
  27. }
  28. class _LoginPageState extends State<LoginPage> {
  29. TextEditingController _phoneNum = TextEditingController(text: '');
  30. TextEditingController _pw = TextEditingController(text: '');
  31. int focus = -1;
  32. bool showBrowse = false;
  33. bool obscureText = true;
  34. @override
  35. void initState() {
  36. // TODO: implement initState
  37. super.initState();
  38. print('MyCookie().reNum===========${MyCookie().reNum}');
  39. EventBus().on('服务器异常,请稍后再试', (arg) {
  40. qAPP();
  41. });
  42. Future.delayed(Duration.zero, () {
  43. MyCookie().reNum = 0;
  44. checkAuditStatus();
  45. if (MyCookie().prefs.getBool('同意协议') == null) {
  46. showDialog(
  47. context: context,
  48. builder: (BuildContext context) {
  49. return Material(
  50. color: Colors.transparent,
  51. child: Center(
  52. child: Container(
  53. height: 220,
  54. margin: EdgeInsets.symmetric(horizontal: 20),
  55. decoration: BoxDecoration(
  56. color: Colors.white,
  57. borderRadius: BorderRadius.circular(15),
  58. ),
  59. child: Column(
  60. children: [
  61. Container(
  62. child:
  63. MyViews().myText('使用协议和隐私政策', MyColors.c333333, 18),
  64. margin: EdgeInsets.only(top: 12),
  65. ),
  66. Expanded(
  67. child: Container(
  68. margin: EdgeInsets.all(12),
  69. child: RichText(
  70. text: TextSpan(
  71. children: [
  72. TextSpan(
  73. text: '《使用协议》',
  74. style: TextStyle(
  75. color: MyColors.cFF4233,
  76. fontSize: 14),
  77. recognizer: TapGestureRecognizer()
  78. ..onTap = () {
  79. MyTools().toPage(
  80. context,
  81. PrivacyPolicyPage(
  82. '使用协议', serviceAgreement),
  83. (then) {});
  84. }),
  85. TextSpan(
  86. text: '和',
  87. style: TextStyle(
  88. color: MyColors.c333333,
  89. fontSize: 14)),
  90. TextSpan(
  91. text: '《隐私政策》',
  92. style: TextStyle(
  93. color: MyColors.cFF4233,
  94. fontSize: 14),
  95. recognizer: TapGestureRecognizer()
  96. ..onTap = () {
  97. MyTools().toPage(
  98. context,
  99. PrivacyPolicyPage(
  100. '隐私政策', privacyPolicy),
  101. (then) {});
  102. }),
  103. TextSpan(
  104. text: '了解详细信息。如你同意,请点击"同意开始接受我们的服务',
  105. style: TextStyle(
  106. color: MyColors.c333333,
  107. fontSize: 14)),
  108. ],
  109. text:
  110. '请你务必审慎阅读、充分理解"使用协议“和“隐私政策"各条款,你可以在"设置"中查看、变更、删除个人信息并管理你的授权。你可阅读',
  111. style: TextStyle(
  112. color: MyColors.c333333, fontSize: 14)),
  113. ),
  114. ),
  115. ),
  116. Container(
  117. height: 0.5,
  118. color: MyColors.cBFBFBF,
  119. ),
  120. Row(
  121. children: [
  122. Expanded(
  123. child: GestureDetector(
  124. onTap: () async {
  125. await SystemChannels.platform
  126. .invokeMethod('SystemNavigator.pop');
  127. },
  128. behavior: HitTestBehavior.translucent,
  129. child: Container(
  130. height: 50,
  131. child: Text(
  132. '暂不使用',
  133. style: TextStyle(
  134. color: MyColors.c333333, fontSize: 20),
  135. ),
  136. alignment: Alignment.center,
  137. ),
  138. ),
  139. ),
  140. Expanded(
  141. child: GestureDetector(
  142. onTap: () {
  143. Navigator.pop(context);
  144. MyCookie().prefs.setBool('同意协议', true);
  145. },
  146. behavior: HitTestBehavior.translucent,
  147. child: Container(
  148. height: 50,
  149. child: Text(
  150. '同意',
  151. style: TextStyle(
  152. color: MyColors.cFF4233, fontSize: 20),
  153. ),
  154. alignment: Alignment.center,
  155. ),
  156. ),
  157. ),
  158. ],
  159. )
  160. ],
  161. ),
  162. ),
  163. ),
  164. );
  165. },
  166. );
  167. }
  168. });
  169. }
  170. @override
  171. void dispose() {
  172. // TODO: implement dispose
  173. super.dispose();
  174. EventBus().off('服务器异常,请稍后再试');
  175. }
  176. @override
  177. Widget build(BuildContext context) {
  178. return GestureDetector(
  179. onTap: () {
  180. MyTools().hideKeyboard(context);
  181. setState(() {
  182. focus = -1;
  183. });
  184. },
  185. child: Scaffold(
  186. body: SingleChildScrollView(
  187. child: Column(
  188. children: [
  189. Container(
  190. height: MediaQuery.of(context).size.height,
  191. child: Column(
  192. children: [
  193. Container(
  194. height: MediaQuery.of(context).size.width * (506 / 750),
  195. child: Stack(
  196. children: [
  197. Image.asset(
  198. 'images/bg_1.png',
  199. width: MediaQuery.of(context).size.width,
  200. height:
  201. MediaQuery.of(context).size.width * (506 / 750),
  202. ),
  203. Positioned(
  204. top: 67,
  205. child: Stack(
  206. children: [
  207. Image.asset(
  208. 'images/yuan_bg.png',
  209. height: 147,
  210. width: 147,
  211. ),
  212. Image.asset(
  213. 'images/logo.png',
  214. height: 90,
  215. width: 90,
  216. )
  217. ],
  218. alignment: Alignment.center,
  219. ),
  220. )
  221. ],
  222. alignment: Alignment.topCenter,
  223. ),
  224. ),
  225. Expanded(
  226. child: Container(
  227. padding: EdgeInsets.only(left: 47, right: 47, top: 26),
  228. child: Column(
  229. children: [
  230. Container(
  231. child: Text(
  232. 'Hello Welcome !',
  233. style: TextStyle(
  234. color: MyColors.cFF4233, fontSize: 24),
  235. ),
  236. margin: EdgeInsets.only(bottom: 25),
  237. ),
  238. Row(
  239. children: [
  240. Container(
  241. width: 22,
  242. height: 22,
  243. child: SvgPicture.asset(
  244. 'images/svg/手机.svg',
  245. height: 22,
  246. width: 22,
  247. ),
  248. ),
  249. Expanded(
  250. child: TextField(
  251. controller: _phoneNum,
  252. cursorColor: MyColors.cFF4233,
  253. cursorWidth: 1.0,
  254. onTap: () {
  255. setState(() {
  256. focus = 0;
  257. });
  258. },
  259. decoration: InputDecoration(
  260. border: InputBorder.none,
  261. disabledBorder: InputBorder.none,
  262. enabledBorder: InputBorder.none,
  263. focusedBorder: InputBorder.none,
  264. isDense: true,
  265. hintText: '请输入手机号',
  266. hintStyle: TextStyle(
  267. color: MyColors.c999999,
  268. fontSize: 16),
  269. contentPadding: const EdgeInsets.fromLTRB(
  270. 14, 4.5, 8, 4.5),
  271. ),
  272. maxLines: 1,
  273. style: TextStyle(
  274. color: MyColors.c333333,
  275. fontSize: 16,
  276. height: 1.3,
  277. letterSpacing: 0.2),
  278. keyboardType: TextInputType.number,
  279. onChanged: (t) {},
  280. ),
  281. )
  282. ],
  283. ),
  284. Container(
  285. height: 1,
  286. color: focus == 0
  287. ? MyColors.cFF4233
  288. : MyColors.cD7D7D7,
  289. margin: EdgeInsets.only(top: 8, bottom: 35),
  290. ),
  291. Row(
  292. children: [
  293. Container(
  294. child: SvgPicture.asset(
  295. 'images/svg/密码.svg',
  296. height: 22,
  297. width: 22,
  298. ),
  299. height: 22,
  300. width: 22,
  301. ),
  302. Expanded(
  303. child: TextField(
  304. controller: _pw,
  305. cursorColor: MyColors.cFF4233,
  306. cursorWidth: 1.0,
  307. onTap: () {
  308. setState(() {
  309. focus = 1;
  310. });
  311. },
  312. decoration: InputDecoration(
  313. border: InputBorder.none,
  314. disabledBorder: InputBorder.none,
  315. enabledBorder: InputBorder.none,
  316. focusedBorder: InputBorder.none,
  317. hintText: '请输入密码',
  318. hintStyle: TextStyle(
  319. color: MyColors.c999999,
  320. fontSize: 16),
  321. isDense: true,
  322. contentPadding:
  323. const EdgeInsets.fromLTRB(
  324. 14, 4.5, 8, 4.5)),
  325. maxLines: 1,
  326. style: TextStyle(
  327. color: MyColors.c333333,
  328. fontSize: 16,
  329. height: 1.3,
  330. letterSpacing: 0.2),
  331. keyboardType: TextInputType.visiblePassword,
  332. obscureText: obscureText,
  333. onChanged: (t) {},
  334. ),
  335. ),
  336. GestureDetector(
  337. onTap: () {
  338. setState(() {
  339. obscureText = !obscureText;
  340. });
  341. },
  342. behavior: HitTestBehavior.translucent,
  343. child: Container(
  344. height: 35,
  345. width: 35,
  346. padding: EdgeInsets.all(6.5),
  347. child: SvgPicture.asset(obscureText
  348. ? 'images/svg/不显示.svg'
  349. : 'images/svg/显示.svg'),
  350. ),
  351. ),
  352. ],
  353. ),
  354. Container(
  355. height: 1,
  356. color: focus == 1
  357. ? MyColors.cFF4233
  358. : MyColors.cD7D7D7,
  359. margin: EdgeInsets.only(top: 8, bottom: 39),
  360. ),
  361. Row(
  362. children: [
  363. Expanded(
  364. child: GestureDetector(
  365. onTap: () {
  366. if (_phoneNum.text.isEmpty ||
  367. _phoneNum.text.length != 11) {
  368. showToast('请填写正确的手机号');
  369. return;
  370. }
  371. if (_pw.text.isEmpty) {
  372. showToast('请填写密码');
  373. return;
  374. }
  375. login();
  376. },
  377. behavior: HitTestBehavior.translucent,
  378. child: Container(
  379. decoration: BoxDecoration(
  380. borderRadius: BorderRadius.all(
  381. Radius.circular(22),
  382. ),
  383. gradient: LinearGradient(
  384. colors: MyColors.lg,
  385. ),
  386. ),
  387. height: 44,
  388. child: Text(
  389. '登 录',
  390. style: TextStyle(
  391. color: Colors.white, fontSize: 17),
  392. ),
  393. alignment: Alignment.center,
  394. padding: EdgeInsets.only(bottom: 2),
  395. ),
  396. ),
  397. ),
  398. Visibility(
  399. child: Container(
  400. width: 20,
  401. ),
  402. visible: showBrowse,
  403. ),
  404. Visibility(
  405. visible: showBrowse,
  406. child: Expanded(
  407. child: GestureDetector(
  408. onTap: () {
  409. guestLogin();
  410. },
  411. behavior: HitTestBehavior.translucent,
  412. child: Container(
  413. decoration: BoxDecoration(
  414. borderRadius: BorderRadius.all(
  415. Radius.circular(22),
  416. ),
  417. gradient: LinearGradient(
  418. colors: MyColors.lg,
  419. ),
  420. ),
  421. height: 44,
  422. child: Text(
  423. '游客登录',
  424. style: TextStyle(
  425. color: Colors.white,
  426. fontSize: 17),
  427. ),
  428. alignment: Alignment.center,
  429. padding: EdgeInsets.only(bottom: 2),
  430. ),
  431. ),
  432. ),
  433. ),
  434. ],
  435. ),
  436. // GestureDetector(
  437. // onTap: () {
  438. // wechatLogin();
  439. // },
  440. // behavior: HitTestBehavior.translucent,
  441. // child: Container(
  442. // decoration: BoxDecoration(
  443. // borderRadius: BorderRadius.all(
  444. // Radius.circular(22),
  445. // ),
  446. // border: Border.all(
  447. // color: MyColors.c333333, width: 1)),
  448. // height: 44,
  449. // child: Row(
  450. // children: [
  451. // Container(
  452. // child:
  453. // SvgPicture.asset('images/svg/微信.svg'),
  454. // margin: EdgeInsets.only(right: 20),
  455. // ),
  456. // Text(
  457. // '微信登录',
  458. // style: TextStyle(
  459. // color: MyColors.c333333,
  460. // fontSize: 17),
  461. // ),
  462. // ],
  463. // mainAxisAlignment: MainAxisAlignment.center,
  464. // ),
  465. // alignment: Alignment.center,
  466. // padding: EdgeInsets.only(bottom: 2),
  467. // margin: EdgeInsets.only(top: 10),
  468. // ),
  469. // ),
  470. // Container(
  471. // alignment: Alignment.centerRight,
  472. // child: GestureDetector(
  473. // onTap: () {
  474. // MyTools().toPage(
  475. // context, RegisteredPage(), (then) {},
  476. // noBack: true);
  477. // },
  478. // behavior: HitTestBehavior.translucent,
  479. // child: Container(
  480. // child: Text(
  481. // '没有账号,去注册',
  482. // style: TextStyle(
  483. // color: MyColors.cFF4233, fontSize: 13),
  484. // ),
  485. // padding: EdgeInsets.all(8),
  486. // margin: EdgeInsets.only(top: 22),
  487. // ),
  488. // ),
  489. // ),
  490. Expanded(
  491. child: SafeArea(
  492. bottom: true,
  493. child: Container(
  494. padding: EdgeInsets.only(bottom: 50),
  495. alignment: Alignment.bottomCenter,
  496. child: Row(
  497. children: [
  498. GestureDetector(
  499. onTap: () {
  500. MyTools().toPage(context,
  501. RegisteredPage(), (then) {},
  502. noBack: true);
  503. },
  504. behavior: HitTestBehavior.translucent,
  505. child: Container(
  506. padding: EdgeInsets.all(8),
  507. child: Text(
  508. '注册账号',
  509. style: TextStyle(
  510. color: MyColors.c666666,
  511. fontSize: 14),
  512. ),
  513. ),
  514. ),
  515. Container(
  516. height: 13,
  517. width: 2,
  518. decoration: BoxDecoration(
  519. borderRadius: BorderRadius.all(
  520. Radius.circular(1)),
  521. color: MyColors.cFF4233,
  522. ),
  523. margin: EdgeInsets.only(
  524. left: 27, right: 27),
  525. ),
  526. GestureDetector(
  527. onTap: () {
  528. MyTools().toPage(context,
  529. ForgetPasswordPage(), (then) {},
  530. noBack: true);
  531. },
  532. behavior: HitTestBehavior.translucent,
  533. child: Container(
  534. padding: EdgeInsets.all(8),
  535. child: Text(
  536. '忘记密码',
  537. style: TextStyle(
  538. color: MyColors.c666666,
  539. fontSize: 14),
  540. ),
  541. ),
  542. ),
  543. ],
  544. mainAxisAlignment: MainAxisAlignment.center,
  545. ),
  546. ),
  547. ),
  548. )
  549. ],
  550. crossAxisAlignment: CrossAxisAlignment.start,
  551. ),
  552. ),
  553. ),
  554. ],
  555. ),
  556. ),
  557. ],
  558. ),
  559. ),
  560. ),
  561. );
  562. }
  563. void login() {
  564. EasyLoading.show();
  565. print(MyCookie().switching);
  566. loginAccount({
  567. 'user': _phoneNum.text,
  568. 'password': MyTools.base64Encode(_pw.text),
  569. 'version': MyCookie().packageInfo.version,
  570. 'phone': Platform.isAndroid ? 'Android' : 'IOS',
  571. 'seq': int.parse(MyCookie().prefs.getString('serverID'))
  572. }, (r, hE) {
  573. if (!hE) {
  574. EasyLoading.dismiss();
  575. LoginInformationBeanEntity entity =
  576. LoginInformationBeanEntity.fromJson(json.decode(r.data.toString()));
  577. MyCookie().saveLoginInformationBeanEntity(entity);
  578. MyDio().initDio();
  579. MyTools().toPage(context, RootPage(), (then) {}, noBack: true);
  580. }
  581. }, (e) {});
  582. }
  583. void checkAuditStatus() {
  584. EasyLoading.show();
  585. MyDio().post(MyApis.getApi('appStoreReview'),
  586. {'version': MyCookie().packageInfo.version}, (response, hasError) {
  587. if (!hasError) {
  588. EasyLoading.dismiss();
  589. AppStoreReviewBeanEntity e = AppStoreReviewBeanEntity.fromJson(
  590. json.decode(response.data.toString()));
  591. print(e.data);
  592. if (e.data && Platform.isIOS) {
  593. setState(() {
  594. showBrowse = true;
  595. MyCookie().underReview = showBrowse;
  596. });
  597. }
  598. }
  599. }, (error) {});
  600. }
  601. void guestLogin() {
  602. MyTools().toPage(context, RootPage1(), (then) {});
  603. }
  604. void qAPP() {
  605. showDialog(
  606. context: context,
  607. builder: (BuildContext context) {
  608. return Material(
  609. color: Colors.black12,
  610. child: Center(
  611. child: Container(
  612. decoration: BoxDecoration(
  613. borderRadius: BorderRadius.circular(16),
  614. color: Colors.white,
  615. ),
  616. height: 180,
  617. margin: EdgeInsets.symmetric(horizontal: 18),
  618. padding: EdgeInsets.symmetric(horizontal: 8, vertical: 12),
  619. child: Column(
  620. children: [
  621. Center(
  622. child: Container(
  623. height: 100,
  624. child: MyViews()
  625. .myText('网络链接异常,请检查您的网络。', MyColors.c333333, 14),
  626. margin: EdgeInsets.symmetric(horizontal: 20),
  627. alignment: Alignment.center,
  628. ),
  629. ),
  630. Container(
  631. height: 0.5,
  632. color: MyColors.cE7E7E7,
  633. margin: EdgeInsets.only(bottom: 12),
  634. ),
  635. Container(
  636. margin: EdgeInsets.symmetric(horizontal: 10),
  637. child: GestureDetector(
  638. behavior: HitTestBehavior.translucent,
  639. onTap: () async {
  640. await SystemChannels.platform
  641. .invokeMethod('SystemNavigator.pop');
  642. },
  643. child: Container(
  644. decoration: BoxDecoration(
  645. borderRadius: BorderRadius.circular(20),
  646. color: MyColors.cFF4233),
  647. height: 40,
  648. child: MyViews().myText('退 出', Colors.white, 14),
  649. alignment: Alignment.center,
  650. ),
  651. ),
  652. )
  653. ],
  654. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  655. ),
  656. ),
  657. ),
  658. );
  659. },
  660. );
  661. }
  662. void wechatLogin() {
  663. }
  664. }