change_password_page.dart 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205
  1. import 'package:bbyyy/https/MyDio.dart';
  2. import 'package:bbyyy/my_tools/easy_loading/easy_loading.dart';
  3. import 'package:bbyyy/my_tools/global.dart';
  4. import 'package:bbyyy/my_tools/my_apis.dart';
  5. import 'package:bbyyy/my_tools/my_colors.dart';
  6. import 'package:bbyyy/my_tools/my_cookie.dart';
  7. import 'package:bbyyy/my_tools/my_tools.dart';
  8. import 'package:bbyyy/my_tools/my_views.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:flutter/services.dart';
  11. import 'package:flutter_svg/svg.dart';
  12. class ChangePasswordPage extends StatefulWidget {
  13. @override
  14. _ChangePasswordPageState createState() => _ChangePasswordPageState();
  15. }
  16. class _ChangePasswordPageState extends State<ChangePasswordPage> {
  17. TextEditingController oldPW = TextEditingController();
  18. TextEditingController newPW = TextEditingController();
  19. bool seeOldPW = true;
  20. bool seeNewPW = true;
  21. @override
  22. Widget build(BuildContext context) {
  23. return GestureDetector(
  24. onTap: (){
  25. MyTools().hideKeyboard(context);
  26. },
  27. behavior: HitTestBehavior.translucent,
  28. child: Scaffold(
  29. body: Column(
  30. children: [
  31. MyViews().myAppBar('修改密码', context, []),
  32. Expanded(
  33. child: SingleChildScrollView(
  34. child: Column(
  35. children: [
  36. Container(
  37. child: Column(
  38. children: [
  39. Container(
  40. child: Row(
  41. children: [
  42. MyViews().myText('旧密码', MyColors.c333333, 16),
  43. Expanded(
  44. child: TextField(
  45. controller: oldPW,
  46. cursorColor: MyColors.cFF4233,
  47. textAlign: TextAlign.end,
  48. cursorWidth: 1.0,
  49. decoration: InputDecoration(
  50. border: InputBorder.none,
  51. disabledBorder: InputBorder.none,
  52. enabledBorder: InputBorder.none,
  53. focusedBorder: InputBorder.none,
  54. isDense: true,
  55. hintText: '请输入旧密码',
  56. hintStyle: TextStyle(
  57. color: MyColors.c999999, fontSize: 16),
  58. contentPadding: const EdgeInsets.fromLTRB(
  59. 14, 4.5, 8, 4.5),
  60. ),
  61. maxLines: 1,
  62. style: TextStyle(
  63. color: MyColors.c333333,
  64. fontSize: 16,
  65. height: 1.3,
  66. letterSpacing: 0.2),
  67. keyboardType: TextInputType.visiblePassword,
  68. obscureText: seeOldPW,
  69. onChanged: (t) {},
  70. )),
  71. GestureDetector(
  72. onTap: () {
  73. setState(() {
  74. seeOldPW = !seeOldPW;
  75. });
  76. },
  77. behavior: HitTestBehavior.translucent,
  78. child: Container(
  79. height: 35,
  80. width: 35,
  81. padding: EdgeInsets.all(6.5),
  82. child: SvgPicture.asset(seeOldPW
  83. ? 'images/svg/不显示.svg'
  84. : 'images/svg/显示.svg',color: MyColors.c333333,),
  85. ),
  86. ),
  87. ],
  88. ),
  89. padding:
  90. EdgeInsets.symmetric(horizontal: 15, vertical: 8),
  91. ),
  92. Container(
  93. height: 0.5,
  94. color: MyColors.cEFEFEF,
  95. ),
  96. Container(
  97. child: Row(
  98. children: [
  99. MyViews().myText('新密码', MyColors.c333333, 16),
  100. Expanded(
  101. child: TextField(
  102. controller: newPW,
  103. cursorColor: MyColors.cFF4233,
  104. textAlign: TextAlign.end,
  105. cursorWidth: 1.0,
  106. decoration: InputDecoration(
  107. border: InputBorder.none,
  108. disabledBorder: InputBorder.none,
  109. enabledBorder: InputBorder.none,
  110. focusedBorder: InputBorder.none,
  111. isDense: true,
  112. hintText: '请输入新密码',
  113. hintStyle: TextStyle(
  114. color: MyColors.c999999, fontSize: 16),
  115. contentPadding: const EdgeInsets.fromLTRB(
  116. 14, 4.5, 8, 4.5),
  117. ),
  118. maxLines: 1,
  119. style: TextStyle(
  120. color: MyColors.c333333,
  121. fontSize: 16,
  122. height: 1.3,
  123. letterSpacing: 0.2),
  124. keyboardType: TextInputType.visiblePassword,
  125. obscureText: seeNewPW,
  126. onChanged: (t) {},
  127. )),
  128. GestureDetector(
  129. onTap: () {
  130. setState(() {
  131. seeNewPW = !seeNewPW;
  132. });
  133. },
  134. behavior: HitTestBehavior.translucent,
  135. child: Container(
  136. height: 35,
  137. width: 35,
  138. padding: EdgeInsets.all(6.5),
  139. child: SvgPicture.asset(seeNewPW
  140. ? 'images/svg/不显示.svg'
  141. : 'images/svg/显示.svg',color: MyColors.c333333,),
  142. ),
  143. ),
  144. ],
  145. ),
  146. padding:
  147. EdgeInsets.symmetric(horizontal: 15, vertical: 8),
  148. ),
  149. ],
  150. ),
  151. color: Colors.white,
  152. margin: EdgeInsets.only(top: 10),
  153. ),
  154. GestureDetector(
  155. onTap: () {
  156. changePassword();
  157. },
  158. behavior: HitTestBehavior.translucent,
  159. child: Container(
  160. color: Colors.white,
  161. height: 50,
  162. margin: EdgeInsets.only(top: 10),
  163. child: MyViews().myText('确认', MyColors.cFF4233, 16),
  164. alignment: Alignment.center,
  165. ),
  166. )
  167. ],
  168. ),
  169. ),
  170. ),
  171. ],
  172. ),
  173. ),
  174. );
  175. }
  176. void changePassword() {
  177. if (oldPW.text.isEmpty) {
  178. showToast('请填写旧密码');
  179. return;
  180. }
  181. if (newPW.text.isEmpty) {
  182. showToast('请填写新密码');
  183. return;
  184. }
  185. // if (oldPW.text.toString() == newPW.text.toString()) {
  186. // showToast('新密码不能与旧密码一致');
  187. // return;
  188. // }
  189. EasyLoading.show();
  190. MyDio().post(MyApis.getApi('changePwd'), {
  191. 'old_password': MyTools.base64Encode(oldPW.text),
  192. 'new_password': MyTools.base64Encode(newPW.text),
  193. }, (response, hasError) {
  194. if (!hasError) {
  195. showToast('修改成功');
  196. MyCookie().clean();
  197. navigatorKey.currentState.pushNamedAndRemoveUntil('/loginPage', ModalRoute.withName("/loginPage"));
  198. }
  199. }, (error) {});
  200. }
  201. }