| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193 |
- import 'package:flutter/material.dart';
- import 'package:flutter_screenutil/flutter_screenutil.dart';
- import 'package:go_router/go_router.dart';
- import 'package:news_app/extension/base.dart';
- import '../../constant/api_const.dart';
- import '../../constant/color_res.dart';
- import '../../http/http_util.dart';
- import '../../model/base_response.dart';
- import '../../util/toast_util.dart';
- import '../../widget/my_txt.dart';
- class UserChangePassword extends StatefulWidget {
- const UserChangePassword({super.key});
- @override
- State<UserChangePassword> createState() => _UserChangePasswordState();
- }
- class _UserChangePasswordState extends State<UserChangePassword> {
- final TextEditingController _oldPasswordController = TextEditingController();
- final TextEditingController _password1Controller = TextEditingController();
- final TextEditingController _password2Controller = TextEditingController();
- @override
- void dispose() {
- // TODO: implement dispose
- _oldPasswordController.dispose();
- _password1Controller.dispose();
- _password2Controller.dispose();
- super.dispose();
- }
- void changePasswordAction() async {
- final password1 = _oldPasswordController.text;
- final password2 = _password1Controller.text;
- final password3 = _password2Controller.text;
- if (password1.isEmpty || password2.isEmpty || password3.isEmpty) {
- showToast("请输入密码");
- return;
- }
- if (password2 != password3) {
- showToast("新密码输入不一致");
- return;
- }
- final result = await HttpUtil().post(
- apiChangePassword,
- data: {"password": password1, "newPassword": password2},
- );
- BaseResponse response = BaseResponse.fromJson(result);
- if (response.isSuccess) {
- showToast('修改成功');
- context.pop();
- } else {
- showToast("${response.msg}");
- }
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- backgroundColor: Colors.white,
- resizeToAvoidBottomInset: false,
- appBar: AppBar(
- title: myTxt(
- text: '重置密码',
- fontSize: 18.sp,
- fontWeight: FontWeight.bold,
- ),
- centerTitle: true,
- ),
- body: Container(
- padding: EdgeInsets.only(left: 16.w, right: 16.w),
- color: Colors.white,
- width: double.infinity,
- height: double.infinity,
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.start,
- children: [
- SizedBox(height: 20.h),
- myTxt(text: "原密码", fontSize: 16.sp, fontWeight: FontWeight.bold),
- SizedBox(height: 16.h),
- TextField(
- obscureText: true,
- controller: _oldPasswordController,
- textInputAction: TextInputAction.done,
- keyboardType: TextInputType.text,
- decoration: InputDecoration(
- // prefixIcon: Icon(
- // Icons.lock_outline,
- // color: Colors.grey,
- // ),
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8.r),
- borderSide: BorderSide.none,
- ),
- filled: true,
- fillColor: colorF5F7FD,
- contentPadding: EdgeInsets.symmetric(
- horizontal: 16.w,
- vertical: 10.h,
- ),
- hintText: '请输入原密码',
- hintStyle: TextStyle(color: Colors.grey),
- ),
- ),
- SizedBox(height: 15.h),
- myTxt(text: "新密码", fontSize: 16.sp, fontWeight: FontWeight.bold),
- SizedBox(height: 16.h),
- TextField(
- obscureText: true,
- controller: _password1Controller,
- textInputAction: TextInputAction.done,
- keyboardType: TextInputType.text,
- decoration: InputDecoration(
- // prefixIcon: Icon(
- // Icons.lock_outline,
- // color: Colors.grey,
- // ),
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8.r),
- borderSide: BorderSide.none,
- ),
- filled: true,
- fillColor: colorF5F7FD,
- contentPadding: EdgeInsets.symmetric(
- horizontal: 16.w,
- vertical: 10.h,
- ),
- hintText: '请输入密码',
- hintStyle: TextStyle(color: Colors.grey),
- ),
- ),
- SizedBox(height: 15.h),
- myTxt(text: "确认新密码", fontSize: 16.sp, fontWeight: FontWeight.bold),
- SizedBox(height: 16.h),
- TextField(
- obscureText: true,
- controller: _password2Controller,
- textInputAction: TextInputAction.done,
- keyboardType: TextInputType.text,
- decoration: InputDecoration(
- // prefixIcon: Icon(
- // Icons.lock_outline,
- // color: Colors.grey,
- // ),
- border: OutlineInputBorder(
- borderRadius: BorderRadius.circular(8.r),
- borderSide: BorderSide.none,
- ),
- filled: true,
- fillColor: colorF5F7FD,
- contentPadding: EdgeInsets.symmetric(
- horizontal: 16.w,
- vertical: 10.h,
- ),
- hintText: '请再次输入密码',
- hintStyle: TextStyle(color: Colors.grey),
- ),
- ),
- SizedBox(height: 20.h),
- // 登录/注册按钮
- GestureDetector(
- onTap: () {
- changePasswordAction();
- },
- child: Container(
- // margin: EdgeInsets.symmetric(horizontal: 28.w),
- height: 42.h,
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(20.r),
- gradient: LinearGradient(
- colors: [color5F59F7, color6592FD],
- begin: Alignment.centerLeft,
- end: Alignment.centerRight,
- ),
- ),
- alignment: Alignment.center,
- child: myTxt(text: "确认", color: Colors.white, fontSize: 15.sp),
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|