import 'package:bbyyy/https/MyDio.dart'; import 'package:bbyyy/my_tools/global.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/my_tools/my_views.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class ChangePasswordPage extends StatefulWidget { @override _ChangePasswordPageState createState() => _ChangePasswordPageState(); } class _ChangePasswordPageState extends State { TextEditingController oldPW = TextEditingController(); TextEditingController newPW = TextEditingController(); @override Widget build(BuildContext context) { return GestureDetector( onTap: (){ MyTools().hideKeyboard(context); }, behavior: HitTestBehavior.translucent, child: Scaffold( body: Column( children: [ MyViews().myAppBar('修改密码', context, []), Expanded( child: SingleChildScrollView( child: Column( children: [ Container( child: Column( children: [ Container( child: Row( children: [ MyViews().myText('旧密码', MyColors.c333333, 16), Expanded( child: TextField( controller: oldPW, cursorColor: MyColors.cFF4233, textAlign: TextAlign.end, cursorWidth: 1.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.visiblePassword, obscureText: true, onChanged: (t) {}, )) ], ), padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8), ), Container( height: 0.5, color: MyColors.cEFEFEF, ), Container( child: Row( children: [ MyViews().myText('新密码', MyColors.c333333, 16), Expanded( child: TextField( controller: newPW, cursorColor: MyColors.cFF4233, textAlign: TextAlign.end, cursorWidth: 1.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.visiblePassword, obscureText: true, onChanged: (t) {}, )) ], ), padding: EdgeInsets.symmetric(horizontal: 15, vertical: 8), ), ], ), color: Colors.white, margin: EdgeInsets.only(top: 10), ), GestureDetector( onTap: () { changePassword(); }, behavior: HitTestBehavior.translucent, child: Container( color: Colors.white, height: 50, margin: EdgeInsets.only(top: 10), child: MyViews().myText('确认', MyColors.c333333, 16), alignment: Alignment.center, ), ) ], ), ), ), ], ), ), ); } void changePassword() { if (oldPW.text.isEmpty) { showToast('请填写旧密码'); return; } if (newPW.text.isEmpty) { showToast('请填写新密码'); return; } // if (oldPW.text.toString() == newPW.text.toString()) { // showToast('新密码不能与旧密码一致'); // return; // } MyDio().post('/ap/changePwd', { 'old_password': MyTools.base64Encode(oldPW.text), 'new_password': MyTools.base64Encode(newPW.text), }, (response, hasError) { if (!hasError) { showToast('修改成功'); MyCookie().clean(); navigatorKey.currentState.pushNamedAndRemoveUntil('/loginPage', ModalRoute.withName("/loginPage")); } }, (error) {}); } }