YSChangePassWord.dart 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122
  1. import 'package:flutter/cupertino.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutterappfuyou/code/YSlogin.dart';
  4. import 'package:flutterappfuyou/code/base/YSBase.dart';
  5. import 'package:flutterappfuyou/code/base/YSNetWorking.dart';
  6. import 'package:shared_preferences/shared_preferences.dart';
  7. class YSChangePassWord extends StatefulWidget {
  8. const YSChangePassWord({Key key}) : super(key: key);
  9. @override
  10. _YSChangePassWordState createState() => _YSChangePassWordState();
  11. }
  12. class _YSChangePassWordState extends State<YSChangePassWord> {
  13. List _showArray = [
  14. {'title':'旧密码','isObscure':true},
  15. {'title':'新密码','isObscure':true},
  16. {'title':'再次输入新密码','isObscure':true},
  17. ];
  18. TextEditingController _newField = TextEditingController();
  19. TextEditingController _passField = TextEditingController();
  20. TextEditingController _wordField = TextEditingController();
  21. @override
  22. void dispose() {
  23. _newField.dispose();
  24. _passField.dispose();
  25. _wordField.dispose();
  26. super.dispose();
  27. }
  28. @override
  29. Widget build(BuildContext context) {
  30. return YSBase(
  31. ysright: GestureDetector(
  32. onTap: () async{
  33. FocusScope.of(context).unfocus();
  34. if(_passField.text.isEmpty){
  35. ysFlutterToast(context, '请输入旧密码');
  36. return;
  37. }
  38. if(_newField.text.isEmpty){
  39. ysFlutterToast(context, '请输入新密码');
  40. return;
  41. }
  42. if(_wordField.text.isEmpty){
  43. ysFlutterToast(context, '请再次输入旧密码');
  44. return;
  45. }
  46. if(_newField.text!=_wordField.text){
  47. ysFlutterToast(context, '两次新密码输入不一致');
  48. return;
  49. }
  50. Map request = {};
  51. request['password_old'] = _passField.text;
  52. request['password_confirm'] = _wordField.text;
  53. request['password_new'] = _newField.text;
  54. Map dict = await ysRequestHttp(context, requestType.post, 'i/changePassword', request);
  55. if(dict!=null){
  56. ysFlutterToast(context, '密码已更改请重新登陆');
  57. SharedPreferences _perfer = await SharedPreferences.getInstance();
  58. _perfer.remove('token');
  59. Navigator.pushAndRemoveUntil(context, MaterialPageRoute(
  60. builder: (context){
  61. return YSLogin(isCheck: true,);
  62. }
  63. ), (route) => false);
  64. }
  65. },
  66. child: Container(
  67. child: Text('提交',style: TextStyle(fontSize: 15,color: Colors.white,decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  68. height: 40,
  69. width: 40,
  70. alignment: Alignment.center,
  71. )
  72. ),
  73. ystitle: '修改密码',
  74. yschild: ListView.separated(
  75. padding: EdgeInsets.only(left: 20,right: 20,top: 20,bottom: 20),
  76. itemBuilder: (context,index){
  77. Map item = _showArray[index];
  78. return Container(
  79. child: LayoutBuilder(
  80. builder: (context,conSize){
  81. return Column(
  82. crossAxisAlignment: CrossAxisAlignment.start,
  83. children: [
  84. Text(item['title'],style: TextStyle(fontSize: 12,color: Color(0xFF808080),decoration: TextDecoration.none,fontWeight: FontWeight.w600),),
  85. Container(
  86. height: 40,
  87. margin: EdgeInsets.only(top: 10),
  88. width: conSize.maxWidth,
  89. child: CupertinoTextField(
  90. placeholder: '请输入',
  91. style: TextStyle(fontSize: 12,color: Color(0xFF808080)),
  92. controller: item['title']=='旧密码'?_passField:item['title']=='再次输入新密码'?_wordField:_newField,
  93. obscureText: item['isObscure'],
  94. suffix: GestureDetector(
  95. onTap: (){
  96. item['isObscure'] = !item['isObscure'];
  97. setState(() {});
  98. },
  99. child: Padding(
  100. padding: EdgeInsets.only(right: 10),
  101. child: Image.asset('lib/images/${item['isObscure']==true?'eye-slash':'eye'}.png',height: 15,width: 15,)
  102. ),
  103. ),
  104. ),
  105. )
  106. ],
  107. );
  108. },
  109. ),
  110. );
  111. },
  112. separatorBuilder: (context,index){
  113. return Container(height: 20,);
  114. },
  115. itemCount: _showArray.length
  116. ),
  117. );
  118. }
  119. }