change_password_page.dart 7.0 KB

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