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 createState() => _UserChangePasswordState(); } class _UserChangePasswordState extends State { 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), ), ), ], ), ), ); } }