login_page.dart 22 KB

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