user_change_password.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:go_router/go_router.dart';
  4. import 'package:news_app/extension/base.dart';
  5. import '../../constant/api_const.dart';
  6. import '../../constant/color_res.dart';
  7. import '../../http/http_util.dart';
  8. import '../../model/base_response.dart';
  9. import '../../util/toast_util.dart';
  10. import '../../widget/my_txt.dart';
  11. class UserChangePassword extends StatefulWidget {
  12. const UserChangePassword({super.key});
  13. @override
  14. State<UserChangePassword> createState() => _UserChangePasswordState();
  15. }
  16. class _UserChangePasswordState extends State<UserChangePassword> {
  17. final TextEditingController _oldPasswordController = TextEditingController();
  18. final TextEditingController _password1Controller = TextEditingController();
  19. final TextEditingController _password2Controller = TextEditingController();
  20. @override
  21. void dispose() {
  22. // TODO: implement dispose
  23. _oldPasswordController.dispose();
  24. _password1Controller.dispose();
  25. _password2Controller.dispose();
  26. super.dispose();
  27. }
  28. void changePasswordAction() async {
  29. final password1 = _oldPasswordController.text;
  30. final password2 = _password1Controller.text;
  31. final password3 = _password2Controller.text;
  32. if (password1.isEmpty || password2.isEmpty || password3.isEmpty) {
  33. showToast("请输入密码");
  34. return;
  35. }
  36. if (password2 != password3) {
  37. showToast("新密码输入不一致");
  38. return;
  39. }
  40. final result = await HttpUtil().post(
  41. apiChangePassword,
  42. data: {"password": password1, "newPassword": password2},
  43. );
  44. BaseResponse response = BaseResponse.fromJson(result);
  45. if (response.isSuccess) {
  46. showToast('修改成功');
  47. context.pop();
  48. } else {
  49. showToast("${response.msg}");
  50. }
  51. }
  52. @override
  53. Widget build(BuildContext context) {
  54. return Scaffold(
  55. backgroundColor: Colors.white,
  56. resizeToAvoidBottomInset: false,
  57. appBar: AppBar(
  58. title: myTxt(
  59. text: '重置密码',
  60. fontSize: 18.sp,
  61. fontWeight: FontWeight.bold,
  62. ),
  63. centerTitle: true,
  64. ),
  65. body: Container(
  66. padding: EdgeInsets.only(left: 16.w, right: 16.w),
  67. color: Colors.white,
  68. width: double.infinity,
  69. height: double.infinity,
  70. child: Column(
  71. crossAxisAlignment: CrossAxisAlignment.start,
  72. children: [
  73. SizedBox(height: 20.h),
  74. myTxt(text: "原密码", fontSize: 16.sp, fontWeight: FontWeight.bold),
  75. SizedBox(height: 16.h),
  76. TextField(
  77. obscureText: true,
  78. controller: _oldPasswordController,
  79. textInputAction: TextInputAction.done,
  80. keyboardType: TextInputType.text,
  81. decoration: InputDecoration(
  82. // prefixIcon: Icon(
  83. // Icons.lock_outline,
  84. // color: Colors.grey,
  85. // ),
  86. border: OutlineInputBorder(
  87. borderRadius: BorderRadius.circular(8.r),
  88. borderSide: BorderSide.none,
  89. ),
  90. filled: true,
  91. fillColor: colorF5F7FD,
  92. contentPadding: EdgeInsets.symmetric(
  93. horizontal: 16.w,
  94. vertical: 10.h,
  95. ),
  96. hintText: '请输入原密码',
  97. hintStyle: TextStyle(color: Colors.grey),
  98. ),
  99. ),
  100. SizedBox(height: 15.h),
  101. myTxt(text: "新密码", fontSize: 16.sp, fontWeight: FontWeight.bold),
  102. SizedBox(height: 16.h),
  103. TextField(
  104. obscureText: true,
  105. controller: _password1Controller,
  106. textInputAction: TextInputAction.done,
  107. keyboardType: TextInputType.text,
  108. decoration: InputDecoration(
  109. // prefixIcon: Icon(
  110. // Icons.lock_outline,
  111. // color: Colors.grey,
  112. // ),
  113. border: OutlineInputBorder(
  114. borderRadius: BorderRadius.circular(8.r),
  115. borderSide: BorderSide.none,
  116. ),
  117. filled: true,
  118. fillColor: colorF5F7FD,
  119. contentPadding: EdgeInsets.symmetric(
  120. horizontal: 16.w,
  121. vertical: 10.h,
  122. ),
  123. hintText: '请输入密码',
  124. hintStyle: TextStyle(color: Colors.grey),
  125. ),
  126. ),
  127. SizedBox(height: 15.h),
  128. myTxt(text: "确认新密码", fontSize: 16.sp, fontWeight: FontWeight.bold),
  129. SizedBox(height: 16.h),
  130. TextField(
  131. obscureText: true,
  132. controller: _password2Controller,
  133. textInputAction: TextInputAction.done,
  134. keyboardType: TextInputType.text,
  135. decoration: InputDecoration(
  136. // prefixIcon: Icon(
  137. // Icons.lock_outline,
  138. // color: Colors.grey,
  139. // ),
  140. border: OutlineInputBorder(
  141. borderRadius: BorderRadius.circular(8.r),
  142. borderSide: BorderSide.none,
  143. ),
  144. filled: true,
  145. fillColor: colorF5F7FD,
  146. contentPadding: EdgeInsets.symmetric(
  147. horizontal: 16.w,
  148. vertical: 10.h,
  149. ),
  150. hintText: '请再次输入密码',
  151. hintStyle: TextStyle(color: Colors.grey),
  152. ),
  153. ),
  154. SizedBox(height: 20.h),
  155. // 登录/注册按钮
  156. GestureDetector(
  157. onTap: () {
  158. changePasswordAction();
  159. },
  160. child: Container(
  161. // margin: EdgeInsets.symmetric(horizontal: 28.w),
  162. height: 42.h,
  163. decoration: BoxDecoration(
  164. borderRadius: BorderRadius.circular(20.r),
  165. gradient: LinearGradient(
  166. colors: [color5F59F7, color6592FD],
  167. begin: Alignment.centerLeft,
  168. end: Alignment.centerRight,
  169. ),
  170. ),
  171. alignment: Alignment.center,
  172. child: myTxt(text: "确认", color: Colors.white, fontSize: 15.sp),
  173. ),
  174. ),
  175. ],
  176. ),
  177. ),
  178. );
  179. }
  180. }