change_password_page.dart 7.1 KB

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