|
|
|
|
@ -29,11 +29,13 @@ class _ResetPasswordViewState extends State<ResetPasswordView> {
|
|
|
|
|
bool _passwordVisible = false;
|
|
|
|
|
bool _confirmPasswordVisible = false;
|
|
|
|
|
|
|
|
|
|
String newPassword = "";
|
|
|
|
|
String confirmPassword = "";
|
|
|
|
|
|
|
|
|
|
final GlobalKey<FormState> _formKey = GlobalKey<FormState>();
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
_userProvider = Provider.of<UserProvider>(context);
|
|
|
|
|
return Form(
|
|
|
|
|
key: _formKey,
|
|
|
|
|
child: Scaffold(
|
|
|
|
|
@ -49,7 +51,7 @@ class _ResetPasswordViewState extends State<ResetPasswordView> {
|
|
|
|
|
context.translation.pleaseEnterTheNewPassword.bodyText2(context).custom(color: AppColor.white20, fontWeight: FontWeight.w500),
|
|
|
|
|
32.height,
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
initialValue: _userProvider.newPassword,
|
|
|
|
|
initialValue: "",
|
|
|
|
|
showBorder: true,
|
|
|
|
|
validator: (value) => Validator.hasValue(value) ? null : context.translation.requiredField,
|
|
|
|
|
labelText: context.translation.password,
|
|
|
|
|
@ -64,12 +66,12 @@ class _ResetPasswordViewState extends State<ResetPasswordView> {
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_userProvider.newPassword = value;
|
|
|
|
|
newPassword = value;
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
16.height,
|
|
|
|
|
AppTextFormField(
|
|
|
|
|
initialValue: _userProvider.confirmPassword,
|
|
|
|
|
initialValue: "",
|
|
|
|
|
labelText: context.translation.confirmPassword,
|
|
|
|
|
obscureText: !_confirmPasswordVisible,
|
|
|
|
|
showBorder: true,
|
|
|
|
|
@ -79,41 +81,42 @@ class _ResetPasswordViewState extends State<ResetPasswordView> {
|
|
|
|
|
? context.translation.requiredField
|
|
|
|
|
: context.translation.passwordLengthMessage,
|
|
|
|
|
onSaved: (value) {
|
|
|
|
|
_userProvider.confirmPassword = value;
|
|
|
|
|
confirmPassword = value;
|
|
|
|
|
},
|
|
|
|
|
suffixIcon: Icon(
|
|
|
|
|
_confirmPasswordVisible ? Icons.visibility : Icons.visibility_off,
|
|
|
|
|
color: context.isDark ? AppColor.neutral10 : AppColor.neutral20,
|
|
|
|
|
).paddingOnly(end: 12).onPress(() { setState(() {
|
|
|
|
|
).paddingOnly(end: 12).onPress(() {
|
|
|
|
|
setState(() {
|
|
|
|
|
_confirmPasswordVisible = !_confirmPasswordVisible;
|
|
|
|
|
}); }),
|
|
|
|
|
});
|
|
|
|
|
}),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
).center.expanded,
|
|
|
|
|
AppFilledButton(label: context.translation.resetPassword, maxWidth: true, onPressed: () => _resetPassword(context: context)),
|
|
|
|
|
AppFilledButton(label: context.translation.resetPassword, maxWidth: true, onPressed: () => _resetPassword(context)),
|
|
|
|
|
],
|
|
|
|
|
).paddingOnly(start: 16, end: 16, bottom: 24, top: 24),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Future<void> _resetPassword({BuildContext context}) async {
|
|
|
|
|
Future<void> _resetPassword(BuildContext context) async {
|
|
|
|
|
if (!_formKey.currentState.validate()) return;
|
|
|
|
|
_formKey.currentState.save();
|
|
|
|
|
if (_userProvider.newPassword != _userProvider.confirmPassword) {
|
|
|
|
|
if (newPassword != confirmPassword) {
|
|
|
|
|
Fluttertoast.showToast(msg: 'Password not matched try again');
|
|
|
|
|
} else {
|
|
|
|
|
UpdatePasswordModel updatePasswordModel = UpdatePasswordModel(
|
|
|
|
|
password: _userProvider.newPassword, confirmPassword: _userProvider.confirmPassword, userId: _userProvider.verifyOtpModel.userId, token: _userProvider.verifyOtpModel.token);
|
|
|
|
|
_userProvider = Provider.of<UserProvider>(context);
|
|
|
|
|
UpdatePasswordModel updatePasswordModel =
|
|
|
|
|
UpdatePasswordModel(password: newPassword, confirmPassword: confirmPassword, userId: _userProvider.verifyOtpModel.userId, token: _userProvider.verifyOtpModel.token);
|
|
|
|
|
GeneralResponseModel generalResponseModel = await _userProvider.updateNewPassword(context: context, updatePasswordModel: updatePasswordModel);
|
|
|
|
|
if (generalResponseModel.isSuccess) {
|
|
|
|
|
_userProvider.newPassword = '';
|
|
|
|
|
_userProvider.confirmPassword = '';
|
|
|
|
|
newPassword = '';
|
|
|
|
|
confirmPassword = '';
|
|
|
|
|
Navigator.of(context).pushNamedAndRemoveUntil(LoginPage.routeName, (routes) => true);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|