login_page.dart 23 KB

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