login_page.dart 18 KB

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