login_page.dart 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392
  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. GestureDetector(
  201. onTap: () {
  202. if (_phoneNum.text.isEmpty ||
  203. _phoneNum.text.length != 11) {
  204. showToast('请填写正确的手机号');
  205. return;
  206. }
  207. if (_pw.text.isEmpty) {
  208. showToast('请填写密码');
  209. return;
  210. }
  211. login();
  212. },
  213. behavior: HitTestBehavior.translucent,
  214. child: Container(
  215. decoration: BoxDecoration(
  216. borderRadius: BorderRadius.all(
  217. Radius.circular(20),
  218. ),
  219. gradient: LinearGradient(
  220. colors: MyColors.lg,
  221. ),
  222. ),
  223. height: 44,
  224. child: Text(
  225. '登 录',
  226. style: TextStyle(
  227. color: Colors.white, fontSize: 17),
  228. ),
  229. alignment: Alignment.center,
  230. padding: EdgeInsets.only(bottom: 2),
  231. ),
  232. ),
  233. Visibility(
  234. visible: showBrowse,
  235. child: GestureDetector(
  236. onTap: () {
  237. guestLogin();
  238. },
  239. behavior: HitTestBehavior.translucent,
  240. child: Container(
  241. margin: EdgeInsets.only(top: 35),
  242. decoration: BoxDecoration(
  243. borderRadius: BorderRadius.all(
  244. Radius.circular(20),
  245. ),
  246. gradient: LinearGradient(
  247. colors: MyColors.lg,
  248. ),
  249. ),
  250. height: 44,
  251. child: Text(
  252. '游客登录',
  253. style: TextStyle(
  254. color: Colors.white, fontSize: 17),
  255. ),
  256. alignment: Alignment.center,
  257. padding: EdgeInsets.only(bottom: 2),
  258. ),
  259. ),
  260. ),
  261. // Container(
  262. // alignment: Alignment.centerRight,
  263. // child: GestureDetector(
  264. // onTap: () {
  265. // MyTools().toPage(
  266. // context, RegisteredPage(), (then) {},
  267. // noBack: true);
  268. // },
  269. // behavior: HitTestBehavior.translucent,
  270. // child: Container(
  271. // child: Text(
  272. // '没有账号,去注册',
  273. // style: TextStyle(
  274. // color: MyColors.cFF4233, fontSize: 13),
  275. // ),
  276. // padding: EdgeInsets.all(8),
  277. // margin: EdgeInsets.only(top: 22),
  278. // ),
  279. // ),
  280. // ),
  281. Expanded(
  282. child: SafeArea(
  283. bottom: true,
  284. child: Container(
  285. padding: EdgeInsets.only(bottom: 50),
  286. alignment: Alignment.bottomCenter,
  287. child: Row(
  288. children: [
  289. GestureDetector(
  290. onTap: () {
  291. MyTools().toPage(
  292. context, RegisteredPage(), (then) {},
  293. noBack: true);
  294. },
  295. behavior: HitTestBehavior.translucent,
  296. child: Container(
  297. padding: EdgeInsets.all(8),
  298. child: Text(
  299. '注册账号',
  300. style: TextStyle(
  301. color: MyColors.c666666, fontSize: 14),
  302. ),
  303. ),
  304. ),
  305. Container(
  306. height: 13,
  307. width: 2,
  308. decoration: BoxDecoration(
  309. borderRadius:
  310. BorderRadius.all(Radius.circular(1)),
  311. color: MyColors.cFF4233,
  312. ),
  313. margin: EdgeInsets.only(left: 27, right: 27),
  314. ),
  315. GestureDetector(
  316. onTap: () {
  317. MyTools().toPage(
  318. context, ForgetPasswordPage(), (then) {},
  319. noBack: true);
  320. },
  321. behavior: HitTestBehavior.translucent,
  322. child: Container(
  323. padding: EdgeInsets.all(8),
  324. child: Text(
  325. '忘记密码',
  326. style: TextStyle(
  327. color: MyColors.c666666, fontSize: 14),
  328. ),
  329. ),
  330. ),
  331. ],
  332. mainAxisAlignment: MainAxisAlignment.center,
  333. ),
  334. ),
  335. ),
  336. )
  337. ],
  338. crossAxisAlignment: CrossAxisAlignment.start,
  339. ),
  340. ),
  341. ),
  342. ],
  343. ),
  344. ),
  345. ],
  346. ),
  347. ),
  348. ),
  349. );
  350. }
  351. void login() {
  352. loginAccount({
  353. 'user': _phoneNum.text,
  354. 'password': MyTools.base64Encode(_pw.text),
  355. 'version':MyCookie().packageInfo.version,
  356. 'phone': Platform.isAndroid?'Android':'IOS'
  357. }, (r, hE) {
  358. if (!hE) {
  359. LoginInformationBeanEntity entity = LoginInformationBeanEntity()
  360. .fromJson(json.decode(r.data.toString()));
  361. MyCookie().saveLoginInformationBeanEntity(entity);
  362. MyDio().initDio();
  363. MyTools().toPage(context, RootPage(), (then) {}, noBack: true);
  364. }
  365. }, (e) {});
  366. }
  367. void checkAuditStatus() {
  368. MyDio().post('/model/appStoreReview', {}, (response, hasError) {
  369. if(!hasError){
  370. AppStoreReviewBeanEntity e = AppStoreReviewBeanEntity().fromJson(json.decode(response.data.toString()));
  371. print(e.data);
  372. if(e.data&&Platform.isIOS){
  373. setState(() {
  374. showBrowse = true;
  375. MyCookie().underReview = showBrowse;
  376. });
  377. }
  378. }
  379. }, (error) { });
  380. }
  381. void guestLogin() {
  382. MyTools().toPage(context, RootPage1(), (then){});
  383. }
  384. }