login_page.dart 28 KB

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