change_password_page.dart 6.9 KB

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