import 'dart:convert'; import 'dart:io'; import 'package:bbyyy/beans/login_information_bean_entity.dart'; import 'package:bbyyy/https/MyDio.dart'; import 'package:bbyyy/https/my_request.dart'; import 'package:bbyyy/my_tools/my_colors.dart'; import 'package:bbyyy/my_tools/my_cookie.dart'; import 'package:bbyyy/my_tools/my_tools.dart'; import 'package:bbyyy/paegs/forget_password_page/forget_password_page.dart'; import 'package:bbyyy/paegs/guest_login_page/root_page.dart'; import 'package:bbyyy/paegs/registered_page/registered_page.dart'; import 'package:bbyyy/paegs/root_page/root_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart';import 'package:bbyyy/beans/app_store_review_bean_entity.dart'; class LoginPage extends StatefulWidget { @override _LoginPageState createState() => _LoginPageState(); } class _LoginPageState extends State { TextEditingController _phoneNum = TextEditingController(text: ''); TextEditingController _pw = TextEditingController(text: ''); int focus = -1; bool showBrowse = false; @override void initState() { // TODO: implement initState super.initState(); checkAuditStatus(); } @override Widget build(BuildContext context) { return GestureDetector( onTap: () { MyTools().hideKeyboard(context); setState(() { focus = -1; }); }, child: Scaffold( body: SingleChildScrollView( child: Column( children: [ Container( height: MediaQuery.of(context).size.height, child: Column( children: [ Container( height: MediaQuery.of(context).size.width * (506 / 750), child: Stack( children: [ Image.asset( 'images/bg_1.png', width: MediaQuery.of(context).size.width, height: MediaQuery.of(context).size.width * (506 / 750), ), Positioned( top: 67, child: Stack( children: [ Image.asset( 'images/yuan_bg.png', height: 147, width: 147, ), Image.asset( 'images/logo.png', height: 90, width: 90, ) ], alignment: Alignment.center, ), ) ], alignment: Alignment.topCenter, ), ), Expanded( child: Container( padding: EdgeInsets.only(left: 47, right: 47, top: 26), child: Column( children: [ Container( child: Text( 'Hello Welcome !', style: TextStyle( color: MyColors.cFF4233, fontSize: 24), ), margin: EdgeInsets.only(bottom: 25), ), Row( children: [ Container( width: 22, height: 22, child: SvgPicture.asset( 'images/svg/手机.svg', height: 22, width: 22, ), ), Expanded( child: TextField( controller: _phoneNum, cursorColor: MyColors.cFF4233, cursorWidth: 1.0, onTap: () { setState(() { focus = 0; }); }, decoration: InputDecoration( border: InputBorder.none, disabledBorder: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, isDense: true, hintText: '请输入手机号', hintStyle: TextStyle( color: MyColors.c999999, fontSize: 16), contentPadding: const EdgeInsets.fromLTRB( 14, 4.5, 8, 4.5), ), maxLines: 1, style: TextStyle( color: MyColors.c333333, fontSize: 16, height: 1.3, letterSpacing: 0.2), keyboardType: TextInputType.number, onChanged: (t) {}, ), ) ], ), Container( height: 1, color: focus == 0 ? MyColors.cFF4233 : MyColors.cD7D7D7, margin: EdgeInsets.only(top: 8, bottom: 35), ), Row( children: [ Container( child: SvgPicture.asset( 'images/svg/密码.svg', height: 22, width: 22, ), height: 22, width: 22, ), Expanded( child: TextField( controller: _pw, cursorColor: MyColors.cFF4233, cursorWidth: 1.0, onTap: () { setState(() { focus = 1; }); }, decoration: InputDecoration( border: InputBorder.none, disabledBorder: InputBorder.none, enabledBorder: InputBorder.none, focusedBorder: InputBorder.none, hintText: '请输入密码', hintStyle: TextStyle( color: MyColors.c999999, fontSize: 16), isDense: true, contentPadding: const EdgeInsets.fromLTRB( 14, 4.5, 8, 4.5)), maxLines: 1, style: TextStyle( color: MyColors.c333333, fontSize: 16, height: 1.3, letterSpacing: 0.2), keyboardType: TextInputType.visiblePassword, obscureText: true, onChanged: (t) {}, ), ) ], ), Container( height: 1, color: focus == 1 ? MyColors.cFF4233 : MyColors.cD7D7D7, margin: EdgeInsets.only(top: 8, bottom: 39), ), Row( children: [ Expanded( child: GestureDetector( onTap: () { if (_phoneNum.text.isEmpty || _phoneNum.text.length != 11) { showToast('请填写正确的手机号'); return; } if (_pw.text.isEmpty) { showToast('请填写密码'); return; } login(); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(22), ), gradient: LinearGradient( colors: MyColors.lg, ), ), height: 44, child: Text( '登 录', style: TextStyle( color: Colors.white, fontSize: 17), ), alignment: Alignment.center, padding: EdgeInsets.only(bottom: 2), ), ), ), Visibility(child: Container(width: 20,),visible: showBrowse,), Visibility( visible: showBrowse, child: Expanded( child: GestureDetector( onTap: () { guestLogin(); }, behavior: HitTestBehavior.translucent, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.all( Radius.circular(22), ), gradient: LinearGradient( colors: MyColors.lg, ), ), height: 44, child: Text( '游客登录', style: TextStyle( color: Colors.white, fontSize: 17), ), alignment: Alignment.center, padding: EdgeInsets.only(bottom: 2), ), ), ), ), ], ), // Container( // alignment: Alignment.centerRight, // child: GestureDetector( // onTap: () { // MyTools().toPage( // context, RegisteredPage(), (then) {}, // noBack: true); // }, // behavior: HitTestBehavior.translucent, // child: Container( // child: Text( // '没有账号,去注册', // style: TextStyle( // color: MyColors.cFF4233, fontSize: 13), // ), // padding: EdgeInsets.all(8), // margin: EdgeInsets.only(top: 22), // ), // ), // ), Expanded( child: SafeArea( bottom: true, child: Container( padding: EdgeInsets.only(bottom: 50), alignment: Alignment.bottomCenter, child: Row( children: [ GestureDetector( onTap: () { MyTools().toPage( context, RegisteredPage(), (then) {}, noBack: true); }, behavior: HitTestBehavior.translucent, child: Container( padding: EdgeInsets.all(8), child: Text( '注册账号', style: TextStyle( color: MyColors.c666666, fontSize: 14), ), ), ), Container( height: 13, width: 2, decoration: BoxDecoration( borderRadius: BorderRadius.all(Radius.circular(1)), color: MyColors.cFF4233, ), margin: EdgeInsets.only(left: 27, right: 27), ), GestureDetector( onTap: () { MyTools().toPage( context, ForgetPasswordPage(), (then) {}, noBack: true); }, behavior: HitTestBehavior.translucent, child: Container( padding: EdgeInsets.all(8), child: Text( '忘记密码', style: TextStyle( color: MyColors.c666666, fontSize: 14), ), ), ), ], mainAxisAlignment: MainAxisAlignment.center, ), ), ), ) ], crossAxisAlignment: CrossAxisAlignment.start, ), ), ), ], ), ), ], ), ), ), ); } void login() { loginAccount({ 'user': _phoneNum.text, 'password': MyTools.base64Encode(_pw.text), 'version':MyCookie().packageInfo.version, 'phone': Platform.isAndroid?'Android':'IOS' }, (r, hE) { if (!hE) { LoginInformationBeanEntity entity = LoginInformationBeanEntity() .fromJson(json.decode(r.data.toString())); MyCookie().saveLoginInformationBeanEntity(entity); MyDio().initDio(); MyTools().toPage(context, RootPage(), (then) {}, noBack: true); } }, (e) {}); } void checkAuditStatus() { MyDio().post('/model/appStoreReview', { 'version':MyCookie().packageInfo.version }, (response, hasError) { if(!hasError){ AppStoreReviewBeanEntity e = AppStoreReviewBeanEntity().fromJson(json.decode(response.data.toString())); print(e.data); if(e.data&&Platform.isIOS){ setState(() { showBrowse = true; MyCookie().underReview = showBrowse; }); } } }, (error) { }); } void guestLogin() { MyTools().toPage(context, RootPage1(), (then){}); } }