import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:crypto/crypto.dart'; import 'dart:convert'; import '../../util/session.dart'; import '../../showAlert.dart'; import '../../util/api.dart'; import '../../util/util.dart'; import '../../login_page.dart'; class RevisePasswordPage extends StatefulWidget { final Widget child; RevisePasswordPage({ Key key, this.child }): super(key: key); _RevisePasswordPageState createState() => _RevisePasswordPageState(); } class _RevisePasswordPageState extends State < RevisePasswordPage > { String oldPassword = ''; String newPassword = ''; bool submitStatus = false; bool loginStatus = true; @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( elevation: 0, title: Text('修改密码', style: TextStyle( fontSize: ScreenUtil.getInstance().setSp(36) ), ), centerTitle: true, backgroundColor: Color.fromRGBO(64, 98, 254, 1), ), body: Container( color: Colors.white, child: Column( children: < Widget > [ Container( padding: EdgeInsets.fromLTRB(ScreenUtil.getInstance().setHeight(55), ScreenUtil.getInstance().setHeight(150), ScreenUtil.getInstance().setHeight(55), 0), child: Column( children: < Widget > [ Padding( padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(60)), child: TextField( obscureText: true, decoration: InputDecoration( border: UnderlineInputBorder(), hintText: "请输入旧密码", hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Color.fromRGBO(155, 155, 155, 1)), ), onChanged: (value) { setState(() { oldPassword = value; }); }, ), ), Padding( padding: EdgeInsets.only(bottom: ScreenUtil.getInstance().setHeight(125)), child: TextField( obscureText: true, cursorColor: Color.fromRGBO(153, 153, 153, 0.5), decoration: InputDecoration( hintText: "请输入新密码", hintStyle: TextStyle(fontSize: ScreenUtil.getInstance().setSp(32), color: Color.fromRGBO(155, 155, 155, 1)), ), onChanged: (value) { setState(() { newPassword = value; }); }, ) ), InkWell( child: Container( height: ScreenUtil.getInstance().setHeight(100), decoration: BoxDecoration( color: (oldPassword != '' && newPassword != '') ? 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 (oldPassword == '' || newPassword == '') { return; } String tempString = sha1.convert(utf8.encode(oldPassword)).toString(); String newTempString = sha1.convert(utf8.encode(newPassword)).toString(); getKey('password').then((value) { if (value != tempString) { showDialog < Null > ( context: context, //BuildContext对象 barrierDismissible: false, builder: (BuildContext context) { return new MyAlertDialog( //调用对话框 text: '旧密码错误,请重新输入', childCallback: (val) {}, ); }); } else { setState(() { loginStatus = false; }); updataPasswrod(tempString, newTempString).then((resp) { if (isNotError(context, resp) && this.mounted) { setKey('password', newTempString); showDialog < Null > ( context: context, //BuildContext对象 barrierDismissible: false, builder: (BuildContext context) { return new MyAlertDialog( //调用对话框 text: '修改成功', childCallback: (val) { if (val) { setState(() { loginStatus = true; }); clearKey(); Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) { return LoginPage(); })); } }, ); }); } }); } }); }, ) ], ), ) ], ), ), resizeToAvoidBottomPadding: false //键盘弹出,页面不跟随向上滑动,防止出现溢出错误 ); } }