forgot password screns logic fixed

This commit is contained in:
amirrezaghabeli
2025-09-22 14:25:59 +03:30
parent a9450a60d7
commit e85ac8d649
13 changed files with 209 additions and 133 deletions
@@ -6,12 +6,12 @@ import 'package:provider/provider.dart';
import 'package:tm_app/core/utils/size_config.dart';
import '../../../core/constants/assets.dart';
import '../../../core/routes/app_routes.dart';
import '../../../core/theme/colors.dart';
import '../../../core/utils/app_toast.dart';
import '../../../view_models/auth_view_model.dart';
import '../../shared/base_button.dart';
import '../strings/forgot_password_otp_strings.dart';
import '../../forget_password_create/pages/forgot_password_create_screen.dart';
class DesktopForgotPasswordOtpPage extends StatefulWidget {
const DesktopForgotPasswordOtpPage({super.key});
@@ -35,16 +35,14 @@ class _DesktopForgotPasswordOtpPageState
void _viewModelListener() {
if (viewModel.errorMessageOtp != null) {
AppToast.error(context, viewModel.errorMessageOtp!);
}
if (viewModel.resetToken != null) {
} else if (!viewModel.isLoadingOtp &&
viewModel.verifyOtpSuccess &&
viewModel.resetToken != null) {
Router.neglect(
context,
() => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const ForgotPasswordCreateScreen()),
),
() => const ForgotPasswordCreateRouteData().pushReplacement(context),
);
viewModel.clearOtpFlow();
}
}
@@ -99,7 +97,7 @@ class _DesktopForgotPasswordOtpPageState
SizedBox(height: 40.0.h()),
Pinput(
controller: viewModel.otpController,
length: 5,
length: 6,
pinAnimationType: PinAnimationType.scale,
defaultPinTheme: PinTheme(
width: 50.0.w(),
@@ -117,20 +115,22 @@ class _DesktopForgotPasswordOtpPageState
),
SizedBox(height: 24.0.h()),
viewModel.isLoadingOtp
? const BaseButton(
isEnabled: false,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: null,
)
? BaseButton(
isEnabled: viewModel.isOtpValid,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: null,
isLoading: true,
)
: BaseButton(
isEnabled: viewModel.canSubmitOtpPage,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: viewModel.canSubmitOtpPage
? () async {
isEnabled: viewModel.canSubmitOtpPage,
text: ForgotPasswordOtpStrings.resetLink,
onPressed:
viewModel.canSubmitOtpPage
? () async {
await viewModel.verifyOtp(context);
}
: null,
),
: null,
),
const SizedBox(height: 12.0),
TextButton(
onPressed: () {
@@ -35,10 +35,11 @@ class _MobileForgotPasswordOtpPageState
void _viewModelListener() {
if (viewModel.errorMessageOtp != null) {
AppToast.error(context, viewModel.errorMessageOtp!);
}
if (viewModel.resetToken != null) {
const ForgotPasswordCreateRouteData().push(context);
} else if (!viewModel.isLoadingOtp &&
viewModel.verifyOtpSuccess &&
viewModel.resetToken != null) {
const ForgotPasswordCreateRouteData().pushReplacement(context);
viewModel.clearOtpFlow();
}
}
@@ -90,7 +91,7 @@ class _MobileForgotPasswordOtpPageState
SizedBox(height: 40.0.h()),
Pinput(
controller: viewModel.otpController,
length: 5,
length: 6,
pinAnimationType: PinAnimationType.scale,
defaultPinTheme: PinTheme(
width: 50.0.w(),
@@ -108,10 +109,11 @@ class _MobileForgotPasswordOtpPageState
),
SizedBox(height: 24.0.h()),
viewModel.isLoadingOtp
? const BaseButton(
isEnabled: false,
? BaseButton(
isEnabled: viewModel.isOtpValid,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: null,
isLoading: true,
)
: BaseButton(
isEnabled: viewModel.canSubmitOtpPage,
@@ -6,12 +6,12 @@ import 'package:provider/provider.dart';
import 'package:tm_app/core/utils/size_config.dart';
import '../../../core/constants/assets.dart';
import '../../../core/routes/app_routes.dart';
import '../../../core/theme/colors.dart';
import '../../../core/utils/app_toast.dart';
import '../../../view_models/auth_view_model.dart';
import '../../shared/base_button.dart';
import '../strings/forgot_password_otp_strings.dart';
import '../../forget_password_create/pages/forgot_password_create_screen.dart';
class TabletForgotPasswordOtpPage extends StatefulWidget {
const TabletForgotPasswordOtpPage({super.key});
@@ -35,16 +35,14 @@ class _TabletForgotPasswordOtpPageState
void _viewModelListener() {
if (viewModel.errorMessageOtp != null) {
AppToast.error(context, viewModel.errorMessageOtp!);
}
if (viewModel.resetToken != null) {
} else if (!viewModel.isLoadingOtp &&
viewModel.verifyOtpSuccess &&
viewModel.resetToken != null) {
Router.neglect(
context,
() => Navigator.push(
context,
MaterialPageRoute(builder: (_) => const ForgotPasswordCreateScreen()),
),
() => const ForgotPasswordCreateRouteData().pushReplacement(context),
);
viewModel.clearOtpFlow();
}
}
@@ -99,7 +97,7 @@ class _TabletForgotPasswordOtpPageState
SizedBox(height: 40.0.h()),
Pinput(
controller: viewModel.otpController,
length: 5,
length: 6,
pinAnimationType: PinAnimationType.scale,
defaultPinTheme: PinTheme(
width: 50.0.w(),
@@ -117,20 +115,22 @@ class _TabletForgotPasswordOtpPageState
),
SizedBox(height: 24.0.h()),
viewModel.isLoadingOtp
? const BaseButton(
isEnabled: false,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: null,
)
? BaseButton(
isEnabled: viewModel.isOtpValid,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: null,
isLoading: true,
)
: BaseButton(
isEnabled: viewModel.canSubmitOtpPage,
text: ForgotPasswordOtpStrings.resetLink,
onPressed: viewModel.canSubmitOtpPage
? () async {
isEnabled: viewModel.canSubmitOtpPage,
text: ForgotPasswordOtpStrings.resetLink,
onPressed:
viewModel.canSubmitOtpPage
? () async {
await viewModel.verifyOtp(context);
}
: null,
),
: null,
),
const SizedBox(height: 12.0),
TextButton(
onPressed: () {