login_page.dart 28 KB

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