YSMineChangePassword.dart 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_tzh/base/YSBase.dart';
  3. import 'package:flutter_tzh/home/view/YSInputView.dart';
  4. import 'package:flutter_tzh/tool/YSTools.dart';
  5. import 'package:shared_preferences/shared_preferences.dart';
  6. import '../login/YSLogin.dart';
  7. import '../tool/YSNetWork.dart';
  8. class YSMineChangePassword extends StatefulWidget {
  9. const YSMineChangePassword({Key? key}) : super(key: key);
  10. @override
  11. YSMineChangePasswordState createState() => YSMineChangePasswordState();
  12. }
  13. class YSMineChangePasswordState extends State<YSMineChangePassword> {
  14. String _password1 = '';
  15. String _password2 = '';
  16. @override
  17. Widget build(BuildContext context) {
  18. return YSBase(
  19. ysTitle: '修改密码',
  20. ysChild: Container(
  21. padding: EdgeInsets.only(left: hsp(20),right: hsp(20),top: hsp(50)),
  22. child: Column(
  23. children: [
  24. YSInputView3(valueSetter: (value) {
  25. _password1 = value;
  26. }, title: '旧密码',isSec: true,),
  27. Padding(
  28. padding: EdgeInsets.only(top: hsp(12),bottom: hsp(61)),
  29. child: YSInputView3(valueSetter: (value) {
  30. _password2 = value;
  31. }, title: '新密码',isSec: true,),
  32. ),
  33. GestureDetector(
  34. onTap: () async{
  35. FocusScope.of(context).unfocus();
  36. if(_password1.isEmpty){
  37. ysFlutterToast('请输入旧密码');
  38. return;
  39. }
  40. if(_password2.isEmpty){
  41. ysFlutterToast('请输入新密码');
  42. return;
  43. }
  44. Map request = {};
  45. request['oldPassword'] = _password1;
  46. request['newPassword'] = _password2;
  47. // LogUtil.d(request);
  48. // return;
  49. YSNetWork.ysRequestHttp(context, type: RequestType.post, api: '/user/resetPassword', parameter: request, successSetter: (dict) async{
  50. ysFlutterToast(dict['msg']);
  51. SharedPreferences prefs = await SharedPreferences.getInstance();
  52. prefs.remove('token');
  53. if(!mounted)return;
  54. Navigator.of(context).pushAndRemoveUntil(MaterialPageRoute(builder: (context){
  55. return const YSLogin();
  56. }), (route) => false);
  57. },isLoading: true);
  58. },
  59. child: Container(
  60. height: hsp(50),
  61. width: ysWidth(context)-hsp(80),
  62. decoration: const BoxDecoration(
  63. color: Color(0xFF09A171),
  64. borderRadius: BorderRadius.all(Radius.circular(8)),
  65. gradient: LinearGradient(colors: [Color(0xFF7ADF8D),Color(0xFF7ADF8D),Color(0xFF8FF0A0)])
  66. ),
  67. alignment: Alignment.center,
  68. child: const Text('确定',style: TextStyle(fontSize: 18,color: Colors.white,fontWeight: FontWeight.bold),),
  69. ),
  70. )
  71. ],
  72. ),
  73. ),
  74. );
  75. }
  76. }