Add forgot password, reset password, and verify OTP providers and view models
- Implemented `ForgotPasswordViewModel`, `ResetPasswordViewModel`, and `VerifyOtpViewModel` for handling respective functionalities. - Created provider functions for lazy loading of these view models in the app. - Updated routing to utilize the new providers for managing state in the forgot password flow. - Refactored UI components to integrate with the new view models, ensuring proper state management and user feedback during operations.
This commit is contained in:
@@ -9,12 +9,13 @@ 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 '../../../view_models/verify_otp_view_model.dart';
|
||||
import '../../shared/base_button.dart';
|
||||
import '../strings/forgot_password_otp_strings.dart';
|
||||
|
||||
class DesktopForgotPasswordOtpPage extends StatefulWidget {
|
||||
const DesktopForgotPasswordOtpPage({super.key});
|
||||
const DesktopForgotPasswordOtpPage({required this.email, super.key});
|
||||
final String email;
|
||||
|
||||
@override
|
||||
State<DesktopForgotPasswordOtpPage> createState() =>
|
||||
@@ -23,24 +24,26 @@ class DesktopForgotPasswordOtpPage extends StatefulWidget {
|
||||
|
||||
class _DesktopForgotPasswordOtpPageState
|
||||
extends State<DesktopForgotPasswordOtpPage> {
|
||||
late final AuthViewModel viewModel;
|
||||
late final VerifyOtpViewModel viewModel;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
viewModel = context.read<AuthViewModel>();
|
||||
viewModel = context.read<VerifyOtpViewModel>();
|
||||
viewModel.addListener(_viewModelListener);
|
||||
}
|
||||
|
||||
void _viewModelListener() {
|
||||
if (viewModel.errorMessageOtp != null) {
|
||||
AppToast.error(context, viewModel.errorMessageOtp!);
|
||||
} else if (!viewModel.isLoadingOtp &&
|
||||
if (viewModel.errorMessage != null) {
|
||||
AppToast.error(context, viewModel.errorMessage!);
|
||||
} else if (!viewModel.isLoading &&
|
||||
viewModel.verifyOtpSuccess &&
|
||||
viewModel.resetToken != null) {
|
||||
Router.neglect(
|
||||
context,
|
||||
() => const ForgotPasswordCreateRouteData().pushReplacement(context),
|
||||
() => ForgotPasswordCreateRouteData(
|
||||
resetToken: viewModel.resetToken!,
|
||||
).pushReplacement(context),
|
||||
);
|
||||
viewModel.clearOtpFlow();
|
||||
}
|
||||
@@ -56,7 +59,7 @@ class _DesktopForgotPasswordOtpPageState
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
backgroundColor: AppColors.backgroundColor,
|
||||
body: Consumer<AuthViewModel>(
|
||||
body: Consumer<VerifyOtpViewModel>(
|
||||
builder: (context, viewModel, _) {
|
||||
return Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
@@ -115,7 +118,7 @@ class _DesktopForgotPasswordOtpPageState
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24.0.h()),
|
||||
viewModel.isLoadingOtp
|
||||
viewModel.isLoading
|
||||
? BaseButton(
|
||||
isEnabled: viewModel.isOtpValid,
|
||||
text: ForgotPasswordOtpStrings.resetLink,
|
||||
@@ -128,7 +131,9 @@ class _DesktopForgotPasswordOtpPageState
|
||||
onPressed:
|
||||
viewModel.canSubmitOtpPage
|
||||
? () async {
|
||||
await viewModel.verifyOtp();
|
||||
await viewModel.verifyOtp(
|
||||
email: widget.email,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
|
||||
@@ -7,15 +7,16 @@ import 'package:tm_app/views/forget_password_otp/pages/t_forget_password_otp_pag
|
||||
import '../../shared/responsive_builder.dart';
|
||||
|
||||
class ForgotPasswordOtpScreen extends StatelessWidget {
|
||||
const ForgotPasswordOtpScreen({super.key});
|
||||
const ForgotPasswordOtpScreen({required this.email, super.key});
|
||||
final String email;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
SizeConfig.init(context);
|
||||
return const ResponsiveBuilder(
|
||||
mobile: MobileForgotPasswordOtpPage(),
|
||||
tablet: TabletForgotPasswordOtpPage(),
|
||||
desktop: DesktopForgotPasswordOtpPage(),
|
||||
return ResponsiveBuilder(
|
||||
mobile: MobileForgotPasswordOtpPage(email: email),
|
||||
tablet: TabletForgotPasswordOtpPage(email: email),
|
||||
desktop: DesktopForgotPasswordOtpPage(email: email),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,12 +9,13 @@ import 'package:tm_app/core/utils/size_config.dart';
|
||||
import '../../../core/constants/assets.dart';
|
||||
import '../../../core/theme/colors.dart';
|
||||
import '../../../core/utils/app_toast.dart';
|
||||
import '../../../view_models/auth_view_model.dart';
|
||||
import '../../../view_models/verify_otp_view_model.dart';
|
||||
import '../../shared/base_button.dart';
|
||||
import '../strings/forgot_password_otp_strings.dart';
|
||||
|
||||
class MobileForgotPasswordOtpPage extends StatefulWidget {
|
||||
const MobileForgotPasswordOtpPage({super.key});
|
||||
const MobileForgotPasswordOtpPage({required this.email, super.key});
|
||||
final String email;
|
||||
|
||||
@override
|
||||
State<MobileForgotPasswordOtpPage> createState() =>
|
||||
@@ -23,22 +24,24 @@ class MobileForgotPasswordOtpPage extends StatefulWidget {
|
||||
|
||||
class _MobileForgotPasswordOtpPageState
|
||||
extends State<MobileForgotPasswordOtpPage> {
|
||||
late final AuthViewModel viewModel;
|
||||
late final VerifyOtpViewModel viewModel;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
viewModel = context.read<AuthViewModel>();
|
||||
viewModel = context.read<VerifyOtpViewModel>();
|
||||
viewModel.addListener(_viewModelListener);
|
||||
}
|
||||
|
||||
void _viewModelListener() {
|
||||
if (viewModel.errorMessageOtp != null) {
|
||||
AppToast.error(context, viewModel.errorMessageOtp!);
|
||||
} else if (!viewModel.isLoadingOtp &&
|
||||
if (viewModel.errorMessage != null) {
|
||||
AppToast.error(context, viewModel.errorMessage!);
|
||||
} else if (!viewModel.isLoading &&
|
||||
viewModel.verifyOtpSuccess &&
|
||||
viewModel.resetToken != null) {
|
||||
const ForgotPasswordCreateRouteData().pushReplacement(context);
|
||||
ForgotPasswordCreateRouteData(
|
||||
resetToken: viewModel.resetToken!,
|
||||
).pushReplacement(context);
|
||||
viewModel.clearOtpFlow();
|
||||
}
|
||||
}
|
||||
@@ -57,7 +60,7 @@ class _MobileForgotPasswordOtpPageState
|
||||
child: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
|
||||
child: Consumer<AuthViewModel>(
|
||||
child: Consumer<VerifyOtpViewModel>(
|
||||
builder: (context, viewModel, _) {
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
@@ -109,7 +112,7 @@ class _MobileForgotPasswordOtpPageState
|
||||
),
|
||||
),
|
||||
SizedBox(height: 24.0.h()),
|
||||
viewModel.isLoadingOtp
|
||||
viewModel.isLoading
|
||||
? BaseButton(
|
||||
isEnabled: viewModel.isOtpValid,
|
||||
text: ForgotPasswordOtpStrings.resetLink,
|
||||
@@ -122,7 +125,9 @@ class _MobileForgotPasswordOtpPageState
|
||||
onPressed:
|
||||
viewModel.canSubmitOtpPage
|
||||
? () async {
|
||||
await viewModel.verifyOtp();
|
||||
await viewModel.verifyOtp(
|
||||
email: widget.email,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
|
||||
@@ -9,12 +9,13 @@ 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 '../../../view_models/verify_otp_view_model.dart';
|
||||
import '../../shared/base_button.dart';
|
||||
import '../strings/forgot_password_otp_strings.dart';
|
||||
|
||||
class TabletForgotPasswordOtpPage extends StatefulWidget {
|
||||
const TabletForgotPasswordOtpPage({super.key});
|
||||
const TabletForgotPasswordOtpPage({required this.email, super.key});
|
||||
final String email;
|
||||
|
||||
@override
|
||||
State<TabletForgotPasswordOtpPage> createState() =>
|
||||
@@ -23,24 +24,26 @@ class TabletForgotPasswordOtpPage extends StatefulWidget {
|
||||
|
||||
class _TabletForgotPasswordOtpPageState
|
||||
extends State<TabletForgotPasswordOtpPage> {
|
||||
late final AuthViewModel viewModel;
|
||||
late final VerifyOtpViewModel viewModel;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
viewModel = context.read<AuthViewModel>();
|
||||
viewModel = context.read<VerifyOtpViewModel>();
|
||||
viewModel.addListener(_viewModelListener);
|
||||
}
|
||||
|
||||
void _viewModelListener() {
|
||||
if (viewModel.errorMessageOtp != null) {
|
||||
AppToast.error(context, viewModel.errorMessageOtp!);
|
||||
} else if (!viewModel.isLoadingOtp &&
|
||||
if (viewModel.errorMessage != null) {
|
||||
AppToast.error(context, viewModel.errorMessage!);
|
||||
} else if (!viewModel.isLoading &&
|
||||
viewModel.verifyOtpSuccess &&
|
||||
viewModel.resetToken != null) {
|
||||
Router.neglect(
|
||||
context,
|
||||
() => const ForgotPasswordCreateRouteData().pushReplacement(context),
|
||||
() => ForgotPasswordCreateRouteData(
|
||||
resetToken: viewModel.resetToken!,
|
||||
).pushReplacement(context),
|
||||
);
|
||||
viewModel.clearOtpFlow();
|
||||
}
|
||||
@@ -59,7 +62,7 @@ class _TabletForgotPasswordOtpPageState
|
||||
body: Center(
|
||||
child: SingleChildScrollView(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
|
||||
child: Consumer<AuthViewModel>(
|
||||
child: Consumer<VerifyOtpViewModel>(
|
||||
builder: (context, viewModel, _) {
|
||||
return Center(
|
||||
child: SizedBox(
|
||||
@@ -114,7 +117,7 @@ class _TabletForgotPasswordOtpPageState
|
||||
),
|
||||
),
|
||||
SizedBox(height: 70.0.h()),
|
||||
viewModel.isLoadingOtp
|
||||
viewModel.isLoading
|
||||
? BaseButton(
|
||||
isEnabled: viewModel.isOtpValid,
|
||||
text: ForgotPasswordOtpStrings.resetLink,
|
||||
@@ -127,7 +130,9 @@ class _TabletForgotPasswordOtpPageState
|
||||
onPressed:
|
||||
viewModel.canSubmitOtpPage
|
||||
? () async {
|
||||
await viewModel.verifyOtp();
|
||||
await viewModel.verifyOtp(
|
||||
email: widget.email,
|
||||
);
|
||||
}
|
||||
: null,
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user