login_page.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:bbyyy/beans/login_information_bean_entity.dart';
  4. import 'package:bbyyy/https/MyDio.dart';
  5. import 'package:bbyyy/https/my_request.dart';
  6. import 'package:bbyyy/my_tools/my_colors.dart';
  7. import 'package:bbyyy/my_tools/my_cookie.dart';
  8. import 'package:bbyyy/my_tools/my_tools.dart';
  9. import 'package:bbyyy/paegs/forget_password_page/forget_password_page.dart';
  10. import 'package:bbyyy/paegs/guest_login_page/root_page.dart';
  11. import 'package:bbyyy/paegs/registered_page/registered_page.dart';
  12. import 'package:bbyyy/paegs/root_page/root_page.dart';
  13. import 'package:flutter/cupertino.dart';
  14. import 'package:flutter/material.dart';
  15. import 'package:flutter_svg/flutter_svg.dart';import 'package:bbyyy/beans/app_store_review_bean_entity.dart';
  16. class LoginPage extends StatefulWidget {
  17. @override
  18. _LoginPageState createState() => _LoginPageState();
  19. }
  20. class _LoginPageState extends State<LoginPage> {
  21. TextEditingController _phoneNum = TextEditingController(text: '');
  22. TextEditingController _pw = TextEditingController(text: '');
  23. int focus = -1;
  24. bool showBrowse = false;
  25. @override
  26. void initState() {
  27. // TODO: implement initState
  28. super.initState();
  29. checkAuditStatus();
  30. }
  31. @override
  32. Widget build(BuildContext context) {
  33. return GestureDetector(
  34. onTap: () {
  35. MyTools().hideKeyboard(context);
  36. setState(() {
  37. focus = -1;
  38. });
  39. },
  40. child: Scaffold(
  41. body: SingleChildScrollView(
  42. child: Column(
  43. children: [
  44. Container(
  45. height: MediaQuery.of(context).size.height,
  46. child: Column(
  47. children: [
  48. Container(
  49. height: MediaQuery.of(context).size.width * (506 / 750),
  50. child: Stack(
  51. children: [
  52. Image.asset(
  53. 'images/bg_1.png',
  54. width: MediaQuery.of(context).size.width,
  55. height:
  56. MediaQuery.of(context).size.width * (506 / 750),
  57. ),
  58. Positioned(
  59. top: 67,
  60. child: Stack(
  61. children: [
  62. Image.asset(
  63. 'images/yuan_bg.png',
  64. height: 147,
  65. width: 147,
  66. ),
  67. Image.asset(
  68. 'images/logo.png',
  69. height: 90,
  70. width: 90,
  71. )
  72. ],
  73. alignment: Alignment.center,
  74. ),
  75. )
  76. ],
  77. alignment: Alignment.topCenter,
  78. ),
  79. ),
  80. Expanded(
  81. child: Container(
  82. padding: EdgeInsets.only(left: 47, right: 47, top: 26),
  83. child: Column(
  84. children: [
  85. Container(
  86. child: Text(
  87. 'Hello Welcome !',
  88. style: TextStyle(
  89. color: MyColors.cFF4233, fontSize: 24),
  90. ),
  91. margin: EdgeInsets.only(bottom: 25),
  92. ),
  93. Row(
  94. children: [
  95. Container(
  96. width: 22,
  97. height: 22,
  98. child: SvgPicture.asset(
  99. 'images/svg/手机.svg',
  100. height: 22,
  101. width: 22,
  102. ),
  103. ),
  104. Expanded(
  105. child: TextField(
  106. controller: _phoneNum,
  107. cursorColor: MyColors.cFF4233,
  108. cursorWidth: 1.0,
  109. onTap: () {
  110. setState(() {
  111. focus = 0;
  112. });
  113. },
  114. decoration: InputDecoration(
  115. border: InputBorder.none,
  116. disabledBorder: InputBorder.none,
  117. enabledBorder: InputBorder.none,
  118. focusedBorder: InputBorder.none,
  119. isDense: true,
  120. hintText: '请输入手机号',
  121. hintStyle: TextStyle(
  122. color: MyColors.c999999,
  123. fontSize: 16),
  124. contentPadding: const EdgeInsets.fromLTRB(
  125. 14, 4.5, 8, 4.5),
  126. ),
  127. maxLines: 1,
  128. style: TextStyle(
  129. color: MyColors.c333333,
  130. fontSize: 16,
  131. height: 1.3,
  132. letterSpacing: 0.2),
  133. keyboardType: TextInputType.number,
  134. onChanged: (t) {},
  135. ),
  136. )
  137. ],
  138. ),
  139. Container(
  140. height: 1,
  141. color: focus == 0
  142. ? MyColors.cFF4233
  143. : MyColors.cD7D7D7,
  144. margin: EdgeInsets.only(top: 8, bottom: 35),
  145. ),
  146. Row(
  147. children: [
  148. Container(
  149. child: SvgPicture.asset(
  150. 'images/svg/密码.svg',
  151. height: 22,
  152. width: 22,
  153. ),
  154. height: 22,
  155. width: 22,
  156. ),
  157. Expanded(
  158. child: TextField(
  159. controller: _pw,
  160. cursorColor: MyColors.cFF4233,
  161. cursorWidth: 1.0,
  162. onTap: () {
  163. setState(() {
  164. focus = 1;
  165. });
  166. },
  167. decoration: InputDecoration(
  168. border: InputBorder.none,
  169. disabledBorder: InputBorder.none,
  170. enabledBorder: InputBorder.none,
  171. focusedBorder: InputBorder.none,
  172. hintText: '请输入密码',
  173. hintStyle: TextStyle(
  174. color: MyColors.c999999,
  175. fontSize: 16),
  176. isDense: true,
  177. contentPadding:
  178. const EdgeInsets.fromLTRB(
  179. 14, 4.5, 8, 4.5)),
  180. maxLines: 1,
  181. style: TextStyle(
  182. color: MyColors.c333333,
  183. fontSize: 16,
  184. height: 1.3,
  185. letterSpacing: 0.2),
  186. keyboardType: TextInputType.visiblePassword,
  187. obscureText: true,
  188. onChanged: (t) {},
  189. ),
  190. )
  191. ],
  192. ),
  193. Container(
  194. height: 1,
  195. color: focus == 1
  196. ? MyColors.cFF4233
  197. : MyColors.cD7D7D7,
  198. margin: EdgeInsets.only(top: 8, bottom: 39),
  199. ),
  200. Row(
  201. children: [
  202. Expanded(
  203. child: GestureDetector(
  204. onTap: () {
  205. if (_phoneNum.text.isEmpty ||
  206. _phoneNum.text.length != 11) {
  207. showToast('请填写正确的手机号');
  208. return;
  209. }
  210. if (_pw.text.isEmpty) {
  211. showToast('请填写密码');
  212. return;
  213. }
  214. login();
  215. },
  216. behavior: HitTestBehavior.translucent,
  217. child: Container(
  218. decoration: BoxDecoration(
  219. borderRadius: BorderRadius.all(
  220. Radius.circular(22),
  221. ),
  222. gradient: LinearGradient(
  223. colors: MyColors.lg,
  224. ),
  225. ),
  226. height: 44,
  227. child: Text(
  228. '登 录',
  229. style: TextStyle(
  230. color: Colors.white, fontSize: 17),
  231. ),
  232. alignment: Alignment.center,
  233. padding: EdgeInsets.only(bottom: 2),
  234. ),
  235. ),
  236. ),
  237. Visibility(child: Container(width: 20,),visible: showBrowse,),
  238. Visibility(
  239. visible: showBrowse,
  240. child: Expanded(
  241. child: GestureDetector(
  242. onTap: () {
  243. guestLogin();
  244. },
  245. behavior: HitTestBehavior.translucent,
  246. child: Container(
  247. decoration: BoxDecoration(
  248. borderRadius: BorderRadius.all(
  249. Radius.circular(22),
  250. ),
  251. gradient: LinearGradient(
  252. colors: MyColors.lg,
  253. ),
  254. ),
  255. height: 44,
  256. child: Text(
  257. '游客登录',
  258. style: TextStyle(
  259. color: Colors.white, fontSize: 17),
  260. ),
  261. alignment: Alignment.center,
  262. padding: EdgeInsets.only(bottom: 2),
  263. ),
  264. ),
  265. ),
  266. ),
  267. ],
  268. ),
  269. // Container(
  270. // alignment: Alignment.centerRight,
  271. // child: GestureDetector(
  272. // onTap: () {
  273. // MyTools().toPage(
  274. // context, RegisteredPage(), (then) {},
  275. // noBack: true);
  276. // },
  277. // behavior: HitTestBehavior.translucent,
  278. // child: Container(
  279. // child: Text(
  280. // '没有账号,去注册',
  281. // style: TextStyle(
  282. // color: MyColors.cFF4233, fontSize: 13),
  283. // ),
  284. // padding: EdgeInsets.all(8),
  285. // margin: EdgeInsets.only(top: 22),
  286. // ),
  287. // ),
  288. // ),
  289. Expanded(
  290. child: SafeArea(
  291. bottom: true,
  292. child: Container(
  293. padding: EdgeInsets.only(bottom: 50),
  294. alignment: Alignment.bottomCenter,
  295. child: Row(
  296. children: [
  297. GestureDetector(
  298. onTap: () {
  299. MyTools().toPage(
  300. context, RegisteredPage(), (then) {},
  301. noBack: true);
  302. },
  303. behavior: HitTestBehavior.translucent,
  304. child: Container(
  305. padding: EdgeInsets.all(8),
  306. child: Text(
  307. '注册账号',
  308. style: TextStyle(
  309. color: MyColors.c666666, fontSize: 14),
  310. ),
  311. ),
  312. ),
  313. Container(
  314. height: 13,
  315. width: 2,
  316. decoration: BoxDecoration(
  317. borderRadius:
  318. BorderRadius.all(Radius.circular(1)),
  319. color: MyColors.cFF4233,
  320. ),
  321. margin: EdgeInsets.only(left: 27, right: 27),
  322. ),
  323. GestureDetector(
  324. onTap: () {
  325. MyTools().toPage(
  326. context, ForgetPasswordPage(), (then) {},
  327. noBack: true);
  328. },
  329. behavior: HitTestBehavior.translucent,
  330. child: Container(
  331. padding: EdgeInsets.all(8),
  332. child: Text(
  333. '忘记密码',
  334. style: TextStyle(
  335. color: MyColors.c666666, fontSize: 14),
  336. ),
  337. ),
  338. ),
  339. ],
  340. mainAxisAlignment: MainAxisAlignment.center,
  341. ),
  342. ),
  343. ),
  344. )
  345. ],
  346. crossAxisAlignment: CrossAxisAlignment.start,
  347. ),
  348. ),
  349. ),
  350. ],
  351. ),
  352. ),
  353. ],
  354. ),
  355. ),
  356. ),
  357. );
  358. }
  359. void login() {
  360. loginAccount({
  361. 'user': _phoneNum.text,
  362. 'password': MyTools.base64Encode(_pw.text),
  363. 'version':MyCookie().packageInfo.version,
  364. 'phone': Platform.isAndroid?'Android':'IOS'
  365. }, (r, hE) {
  366. if (!hE) {
  367. LoginInformationBeanEntity entity = LoginInformationBeanEntity()
  368. .fromJson(json.decode(r.data.toString()));
  369. MyCookie().saveLoginInformationBeanEntity(entity);
  370. MyDio().initDio();
  371. MyTools().toPage(context, RootPage(), (then) {}, noBack: true);
  372. }
  373. }, (e) {});
  374. }
  375. void checkAuditStatus() {
  376. MyDio().post('/model/appStoreReview', {
  377. 'version':MyCookie().packageInfo.version
  378. }, (response, hasError) {
  379. if(!hasError){
  380. AppStoreReviewBeanEntity e = AppStoreReviewBeanEntity().fromJson(json.decode(response.data.toString()));
  381. print(e.data);
  382. if(e.data&&Platform.isIOS){
  383. setState(() {
  384. showBrowse = true;
  385. MyCookie().underReview = showBrowse;
  386. });
  387. }
  388. }
  389. }, (error) { });
  390. }
  391. void guestLogin() {
  392. MyTools().toPage(context, RootPage1(), (then){});
  393. }
  394. }