| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'util/session.dart';
- import 'home_page.dart';
- import 'util/api.dart';
- import 'util/util.dart';
- import 'util/models.dart';
- class LoginPage extends StatefulWidget {
- LoginPage({
- Key key,
- }): super(key: key);
- _LoginPageState createState() => _LoginPageState();
- }
- class _LoginPageState extends State < LoginPage > {
- String phone ='';
- String password='';
- bool loginStatus = true;
- @override
- Widget build(BuildContext context) {
- ScreenUtil.instance = ScreenUtil(width: 750, height: 1334,allowFontScaling:false)..init(context);
- return Scaffold(
- body: Container(
- color: Colors.white,
- child: ListView(
- children: < Widget > [
- Container(
- padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(55), 0, ScreenUtil.getInstance().setHeight(55), 0),
- child: Column(
- children: < Widget > [
- Padding(
- padding: EdgeInsets.fromLTRB(0, ScreenUtil.getInstance().setHeight(150), 0, ScreenUtil.getInstance().setHeight(60)),
- child: Center(
- child: Image.asset(
- 'lib/images/icon_logo.png',
- width: ScreenUtil.getInstance().setWidth(210),
- height: ScreenUtil.getInstance().setHeight(210),
- fit: BoxFit.cover,
- ),
- ),
- ),
- Padding(
- padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(60)),
- child: TextField(
- keyboardType: TextInputType.phone,
- decoration: InputDecoration(
- border: UnderlineInputBorder(),
- hintText: "请输入手机号",
- hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Color.fromRGBO(155, 155, 155, 1)),
- ),
- onChanged: (value){
- setState(() {
- phone = value;
- });
- },
- ),
- ),
- Padding(
- padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(125)),
- child: TextField(
- cursorColor: Color.fromRGBO(153, 153, 153, 0.5),
- keyboardType: TextInputType.text,
- obscureText:true,
- decoration: InputDecoration(
- hintText: "请输入密码",
- hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Color.fromRGBO(155, 155, 155, 1)),
- ),
- onChanged: (value){
- setState(() {
- password =value;
- });
- },
- )
- ),
- InkWell(
- child: Container(
- height: ScreenUtil.getInstance().setHeight(100),
- decoration: BoxDecoration(
- color: (phone!=""&&password!="")?Color.fromRGBO(64, 98, 254, 1):Colors.grey,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Center(
- child:Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Offstage(
- offstage: loginStatus,
- child: SizedBox(
- width: ScreenUtil.getInstance().setWidth(45),
- height: ScreenUtil.getInstance().setHeight(45),
- child: Image.asset('lib/images/loading.gif'),
- ),
- ),
- Text('登录', style: TextStyle(fontSize: ScreenUtil.getInstance().setSp(36), color: Colors.white)),
- ],
- )
- ),
- ),
- onTap: () {
- if(phone=='' || password==''){
- return;
- }
- if(!loginStatus) return;//防止重复提交
- setState(() {
- loginStatus = false;
- });
- login(phone,password).then((resp){
- if(isNotError(context, resp)){
- Login loginObj = Login.fromJson(resp.data);
- setKey('token', loginObj.data.token);
- setKey('phone',phone);
- setKey('password',password);
- setKey('nickName',loginObj.data.nickName);
- setKey('printType','1');//设置打印类型
- setKey('stationId', loginObj.data.stationId);//设置站点id
- Navigator.pushReplacement(context, MaterialPageRoute(builder: (context){
- return HomePage();
- }));
- }else{
- setState(() {
- loginStatus = true;
- });
- }
- });
- },
- )
- ],
- ),
- )
- ],
- ),
- ),
- );
- }
- }
|