Merge pull request 'Fixed password and otp bugs' (#143) from forgot_otp_bugs into main
Reviewed-on: https://repo.ravanertebat.com/TM/tm_app/pulls/143
This commit is contained in:
@@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:tm_app/views/completion_of_documents/pages/m_completion_of_documents_page.dart';
|
import 'package:tm_app/views/completion_of_documents/pages/m_completion_of_documents_page.dart';
|
||||||
import 'package:tm_app/views/detail/pages/detail_screen.dart';
|
import 'package:tm_app/views/detail/pages/detail_screen.dart';
|
||||||
|
import 'package:tm_app/views/forget_password_create/pages/forgot_password_create_screen.dart';
|
||||||
import 'package:tm_app/views/forget_password_otp.dart/pages/forgot_password_otp_screen.dart';
|
import 'package:tm_app/views/forget_password_otp.dart/pages/forgot_password_otp_screen.dart';
|
||||||
import 'package:tm_app/views/home/pages/home_screen.dart';
|
import 'package:tm_app/views/home/pages/home_screen.dart';
|
||||||
import 'package:tm_app/views/liked_tenders/pages/liked_tenders_screen.dart';
|
import 'package:tm_app/views/liked_tenders/pages/liked_tenders_screen.dart';
|
||||||
@@ -243,3 +244,14 @@ class ForgotPasswordOtpRouteData extends GoRouteData
|
|||||||
return const ForgotPasswordOtpScreen();
|
return const ForgotPasswordOtpScreen();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TypedGoRoute<ForgotPasswordCreateRouteData>(path: '/forgot-password-create')
|
||||||
|
class ForgotPasswordCreateRouteData extends GoRouteData
|
||||||
|
with _$ForgotPasswordCreateRouteData {
|
||||||
|
const ForgotPasswordCreateRouteData();
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context, GoRouterState state) {
|
||||||
|
return const ForgotPasswordCreateScreen();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -16,6 +16,7 @@ List<RouteBase> get $appRoutes => [
|
|||||||
$tenderDetailRouteData,
|
$tenderDetailRouteData,
|
||||||
$forgotPasswordRouteData,
|
$forgotPasswordRouteData,
|
||||||
$forgotPasswordOtpRouteData,
|
$forgotPasswordOtpRouteData,
|
||||||
|
$forgotPasswordCreateRouteData,
|
||||||
];
|
];
|
||||||
|
|
||||||
RouteBase get $loginScreenRoute =>
|
RouteBase get $loginScreenRoute =>
|
||||||
@@ -371,3 +372,30 @@ mixin _$ForgotPasswordOtpRouteData on GoRouteData {
|
|||||||
@override
|
@override
|
||||||
void replace(BuildContext context) => context.replace(location);
|
void replace(BuildContext context) => context.replace(location);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
RouteBase get $forgotPasswordCreateRouteData => GoRouteData.$route(
|
||||||
|
path: '/forgot-password-create',
|
||||||
|
|
||||||
|
factory: _$ForgotPasswordCreateRouteData._fromState,
|
||||||
|
);
|
||||||
|
|
||||||
|
mixin _$ForgotPasswordCreateRouteData on GoRouteData {
|
||||||
|
static ForgotPasswordCreateRouteData _fromState(GoRouterState state) =>
|
||||||
|
const ForgotPasswordCreateRouteData();
|
||||||
|
|
||||||
|
@override
|
||||||
|
String get location => GoRouteData.$location('/forgot-password-create');
|
||||||
|
|
||||||
|
@override
|
||||||
|
void go(BuildContext context) => context.go(location);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Future<T?> push<T>(BuildContext context) => context.push<T>(location);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void pushReplacement(BuildContext context) =>
|
||||||
|
context.pushReplacement(location);
|
||||||
|
|
||||||
|
@override
|
||||||
|
void replace(BuildContext context) => context.replace(location);
|
||||||
|
}
|
||||||
|
|||||||
@@ -2,5 +2,6 @@ class AuthApi {
|
|||||||
static const String login = '/api/v1/profile/login';
|
static const String login = '/api/v1/profile/login';
|
||||||
static const String logout = '/api/v1/profile/logout';
|
static const String logout = '/api/v1/profile/logout';
|
||||||
static const String forgotPassword = '/api/v1/profile/forgot-password';
|
static const String forgotPassword = '/api/v1/profile/forgot-password';
|
||||||
|
static const String forgotPasswordOtp = '/api/v1/profile/verify-otp';
|
||||||
static const String resetPassword = '/api/v1/profile/reset-password';
|
static const String resetPassword = '/api/v1/profile/reset-password';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -96,7 +96,7 @@ class AuthService {
|
|||||||
final data = jsonEncode({"code": code, "email": email});
|
final data = jsonEncode({"code": code, "email": email});
|
||||||
|
|
||||||
final result = await _networkManager.makeRequest(
|
final result = await _networkManager.makeRequest(
|
||||||
"/api/v1/profile/verify-otp",
|
AuthApi.forgotPasswordOtp,
|
||||||
method: 'POST',
|
method: 'POST',
|
||||||
(json) => VerifyOtpResponseModel.fromJson(json),
|
(json) => VerifyOtpResponseModel.fromJson(json),
|
||||||
data: data,
|
data: data,
|
||||||
|
|||||||
@@ -1,8 +1,9 @@
|
|||||||
|
import 'dart:developer';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:tm_app/data/services/model/customer/customer.dart';
|
import 'package:tm_app/data/services/model/customer/customer.dart';
|
||||||
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
|
import 'package:tm_app/data/services/model/forgot_password_response/forgot_password_response_model.dart';
|
||||||
import 'package:tm_app/data/services/model/verify_otp_response/verify_otp_response_model.dart';
|
import 'package:tm_app/data/services/model/verify_otp_response/verify_otp_response_model.dart';
|
||||||
import 'package:tm_app/views/forget_password_create/pages/forgot_password_create_screen.dart';
|
|
||||||
|
|
||||||
import '../core/utils/result.dart';
|
import '../core/utils/result.dart';
|
||||||
import '../data/repositories/auth_repository.dart';
|
import '../data/repositories/auth_repository.dart';
|
||||||
@@ -51,11 +52,20 @@ class AuthViewModel with ChangeNotifier {
|
|||||||
Customer? _loggedInUser;
|
Customer? _loggedInUser;
|
||||||
String? successMessage;
|
String? successMessage;
|
||||||
String? _forgotPasswordMessage;
|
String? _forgotPasswordMessage;
|
||||||
|
bool _isLoadingForgot = false;
|
||||||
|
bool _isLoadingOtp = false;
|
||||||
|
String? _errorMessageForget;
|
||||||
|
String? _errorMessageOtp;
|
||||||
|
|
||||||
bool get isLoading => _isLoading;
|
bool get isLoading => _isLoading;
|
||||||
|
bool get isLoadingForgot => _isLoadingForgot;
|
||||||
|
bool get isLoadingOtp => _isLoadingOtp;
|
||||||
bool get isResetPasswordLoading => _isResetPasswordLoading;
|
bool get isResetPasswordLoading => _isResetPasswordLoading;
|
||||||
String? get errorMessage => _errorMessage;
|
String? get errorMessage => _errorMessage;
|
||||||
|
String? get errorMessageForget => _errorMessageForget;
|
||||||
String? get resetPasswordErrorMessage => _resetPasswordErrorMessage;
|
String? get resetPasswordErrorMessage => _resetPasswordErrorMessage;
|
||||||
|
String? get errorMessageOtp => _errorMessageOtp;
|
||||||
|
|
||||||
Customer? get loggedInUser => _loggedInUser;
|
Customer? get loggedInUser => _loggedInUser;
|
||||||
String? get forgotPasswordMessage => _forgotPasswordMessage;
|
String? get forgotPasswordMessage => _forgotPasswordMessage;
|
||||||
String? resetToken;
|
String? resetToken;
|
||||||
@@ -159,8 +169,8 @@ class AuthViewModel with ChangeNotifier {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> forgotPassword(BuildContext context) async {
|
Future<void> forgotPassword(BuildContext context) async {
|
||||||
_isLoading = true;
|
_isLoadingForgot = true;
|
||||||
_errorMessage = null;
|
_errorMessageForget = null;
|
||||||
successMessage = null;
|
successMessage = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
@@ -170,31 +180,35 @@ class AuthViewModel with ChangeNotifier {
|
|||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case Ok<ForgotPasswordResponseModel>():
|
case Ok<ForgotPasswordResponseModel>():
|
||||||
_isLoading = false;
|
_isLoadingForgot = false;
|
||||||
successMessage = result.value.message;
|
successMessage = result.value.message;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
log('$successMessage');
|
||||||
|
|
||||||
Future.microtask(() {
|
|
||||||
successMessage = null;
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Error<ForgotPasswordResponseModel>():
|
case Error<ForgotPasswordResponseModel>():
|
||||||
_isLoading = false;
|
_isLoadingForgot = false;
|
||||||
_errorMessage = result.error.toString();
|
_errorMessageForget = result.error.toString();
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
|
||||||
Future.microtask(() {
|
Future.microtask(() {
|
||||||
_errorMessage = null;
|
_errorMessageForget = null;
|
||||||
});
|
});
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> verifyOtp(BuildContext context) async {
|
void clearMessages() {
|
||||||
_isLoading = true;
|
successMessage = null;
|
||||||
_errorMessage = null;
|
_errorMessage = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> verifyOtp(BuildContext context) async {
|
||||||
|
_isLoadingOtp = true;
|
||||||
|
_errorMessageOtp = null;
|
||||||
|
notifyListeners();
|
||||||
|
|
||||||
final result = await _authRepository.verifyOtp(
|
final result = await _authRepository.verifyOtp(
|
||||||
code: otpController.text.trim(),
|
code: otpController.text.trim(),
|
||||||
@@ -203,22 +217,19 @@ class AuthViewModel with ChangeNotifier {
|
|||||||
|
|
||||||
switch (result) {
|
switch (result) {
|
||||||
case Ok<VerifyOtpResponseModel>():
|
case Ok<VerifyOtpResponseModel>():
|
||||||
_isLoading = false;
|
_isLoadingOtp = false;
|
||||||
resetToken = result.value.data.token;
|
resetToken = result.value.data.token;
|
||||||
|
|
||||||
Navigator.push(
|
|
||||||
context,
|
|
||||||
MaterialPageRoute(builder: (_) => const ForgotPasswordCreateScreen()),
|
|
||||||
);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case Error<VerifyOtpResponseModel>():
|
case Error<VerifyOtpResponseModel>():
|
||||||
_isLoading = false;
|
_isLoadingOtp = false;
|
||||||
_errorMessage = result.error.toString();
|
_errorMessageOtp = result.error.toString();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
_errorMessage = null;
|
|
||||||
|
_errorMessageOtp = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -7,13 +7,53 @@ import 'package:tm_app/core/utils/size_config.dart';
|
|||||||
|
|
||||||
import '../../../core/constants/assets.dart';
|
import '../../../core/constants/assets.dart';
|
||||||
import '../../../core/theme/colors.dart';
|
import '../../../core/theme/colors.dart';
|
||||||
|
import '../../../core/utils/app_toast.dart';
|
||||||
import '../../../view_models/auth_view_model.dart';
|
import '../../../view_models/auth_view_model.dart';
|
||||||
import '../../shared/base_button.dart';
|
import '../../shared/base_button.dart';
|
||||||
import '../strings/forgot_password_otp_strings.dart';
|
import '../strings/forgot_password_otp_strings.dart';
|
||||||
|
import '../../forget_password_create/pages/forgot_password_create_screen.dart';
|
||||||
|
|
||||||
class DesktopForgotPasswordOtpPage extends StatelessWidget {
|
class DesktopForgotPasswordOtpPage extends StatefulWidget {
|
||||||
const DesktopForgotPasswordOtpPage({super.key});
|
const DesktopForgotPasswordOtpPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DesktopForgotPasswordOtpPage> createState() =>
|
||||||
|
_DesktopForgotPasswordOtpPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DesktopForgotPasswordOtpPageState
|
||||||
|
extends State<DesktopForgotPasswordOtpPage> {
|
||||||
|
late final AuthViewModel viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
viewModel = context.read<AuthViewModel>();
|
||||||
|
viewModel.addListener(_viewModelListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _viewModelListener() {
|
||||||
|
if (viewModel.errorMessageOtp != null) {
|
||||||
|
AppToast.error(context, viewModel.errorMessageOtp!);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewModel.resetToken != null) {
|
||||||
|
Router.neglect(
|
||||||
|
context,
|
||||||
|
() => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (_) => const ForgotPasswordCreateScreen()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
viewModel.removeListener(_viewModelListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -26,7 +66,6 @@ class DesktopForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
return Center(
|
return Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 364,
|
width: 364,
|
||||||
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -62,9 +101,6 @@ class DesktopForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
controller: viewModel.otpController,
|
controller: viewModel.otpController,
|
||||||
length: 5,
|
length: 5,
|
||||||
pinAnimationType: PinAnimationType.scale,
|
pinAnimationType: PinAnimationType.scale,
|
||||||
onCompleted: (value) {
|
|
||||||
debugPrint('OTP: $value');
|
|
||||||
},
|
|
||||||
defaultPinTheme: PinTheme(
|
defaultPinTheme: PinTheme(
|
||||||
width: 50.0.w(),
|
width: 50.0.w(),
|
||||||
height: 50.0.h(),
|
height: 50.0.h(),
|
||||||
@@ -80,7 +116,7 @@ class DesktopForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 24.0.h()),
|
SizedBox(height: 24.0.h()),
|
||||||
viewModel.isLoading
|
viewModel.isLoadingOtp
|
||||||
? const BaseButton(
|
? const BaseButton(
|
||||||
isEnabled: false,
|
isEnabled: false,
|
||||||
text: ForgotPasswordOtpStrings.resetLink,
|
text: ForgotPasswordOtpStrings.resetLink,
|
||||||
@@ -89,15 +125,13 @@ class DesktopForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
: BaseButton(
|
: BaseButton(
|
||||||
isEnabled: viewModel.canSubmitOtpPage,
|
isEnabled: viewModel.canSubmitOtpPage,
|
||||||
text: ForgotPasswordOtpStrings.resetLink,
|
text: ForgotPasswordOtpStrings.resetLink,
|
||||||
onPressed:
|
onPressed: viewModel.canSubmitOtpPage
|
||||||
viewModel.canSubmitOtpPage
|
|
||||||
? () async {
|
? () async {
|
||||||
await viewModel.verifyOtp(context);
|
await viewModel.verifyOtp(context);
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12.0),
|
const SizedBox(height: 12.0),
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
|
|||||||
@@ -3,17 +3,51 @@ import 'package:flutter_svg/svg.dart';
|
|||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
import 'package:pinput/pinput.dart';
|
import 'package:pinput/pinput.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
import 'package:tm_app/core/routes/app_routes.dart';
|
||||||
import 'package:tm_app/core/utils/size_config.dart';
|
import 'package:tm_app/core/utils/size_config.dart';
|
||||||
|
|
||||||
import '../../../core/constants/assets.dart';
|
import '../../../core/constants/assets.dart';
|
||||||
import '../../../core/theme/colors.dart';
|
import '../../../core/theme/colors.dart';
|
||||||
|
import '../../../core/utils/app_toast.dart';
|
||||||
import '../../../view_models/auth_view_model.dart';
|
import '../../../view_models/auth_view_model.dart';
|
||||||
import '../../shared/base_button.dart';
|
import '../../shared/base_button.dart';
|
||||||
import '../strings/forgot_password_otp_strings.dart';
|
import '../strings/forgot_password_otp_strings.dart';
|
||||||
|
|
||||||
class MobileForgotPasswordOtpPage extends StatelessWidget {
|
class MobileForgotPasswordOtpPage extends StatefulWidget {
|
||||||
const MobileForgotPasswordOtpPage({super.key});
|
const MobileForgotPasswordOtpPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MobileForgotPasswordOtpPage> createState() =>
|
||||||
|
_MobileForgotPasswordOtpPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MobileForgotPasswordOtpPageState
|
||||||
|
extends State<MobileForgotPasswordOtpPage> {
|
||||||
|
late final AuthViewModel viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
viewModel = context.read<AuthViewModel>();
|
||||||
|
viewModel.addListener(_viewModelListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _viewModelListener() {
|
||||||
|
if (viewModel.errorMessageOtp != null) {
|
||||||
|
AppToast.error(context, viewModel.errorMessageOtp!);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewModel.resetToken != null) {
|
||||||
|
const ForgotPasswordCreateRouteData().push(context);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
viewModel.removeListener(_viewModelListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -58,9 +92,6 @@ class MobileForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
controller: viewModel.otpController,
|
controller: viewModel.otpController,
|
||||||
length: 5,
|
length: 5,
|
||||||
pinAnimationType: PinAnimationType.scale,
|
pinAnimationType: PinAnimationType.scale,
|
||||||
onCompleted: (value) {
|
|
||||||
debugPrint('OTP: $value');
|
|
||||||
},
|
|
||||||
defaultPinTheme: PinTheme(
|
defaultPinTheme: PinTheme(
|
||||||
width: 50.0.w(),
|
width: 50.0.w(),
|
||||||
height: 50.0.h(),
|
height: 50.0.h(),
|
||||||
@@ -76,7 +107,7 @@ class MobileForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 24.0.h()),
|
SizedBox(height: 24.0.h()),
|
||||||
viewModel.isLoading
|
viewModel.isLoadingOtp
|
||||||
? const BaseButton(
|
? const BaseButton(
|
||||||
isEnabled: false,
|
isEnabled: false,
|
||||||
text: ForgotPasswordOtpStrings.resetLink,
|
text: ForgotPasswordOtpStrings.resetLink,
|
||||||
@@ -92,7 +123,6 @@ class MobileForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
|
|||||||
@@ -7,13 +7,53 @@ import 'package:tm_app/core/utils/size_config.dart';
|
|||||||
|
|
||||||
import '../../../core/constants/assets.dart';
|
import '../../../core/constants/assets.dart';
|
||||||
import '../../../core/theme/colors.dart';
|
import '../../../core/theme/colors.dart';
|
||||||
|
import '../../../core/utils/app_toast.dart';
|
||||||
import '../../../view_models/auth_view_model.dart';
|
import '../../../view_models/auth_view_model.dart';
|
||||||
import '../../shared/base_button.dart';
|
import '../../shared/base_button.dart';
|
||||||
import '../strings/forgot_password_otp_strings.dart';
|
import '../strings/forgot_password_otp_strings.dart';
|
||||||
|
import '../../forget_password_create/pages/forgot_password_create_screen.dart';
|
||||||
|
|
||||||
class TabletForgotPasswordOtpPage extends StatelessWidget {
|
class TabletForgotPasswordOtpPage extends StatefulWidget {
|
||||||
const TabletForgotPasswordOtpPage({super.key});
|
const TabletForgotPasswordOtpPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<TabletForgotPasswordOtpPage> createState() =>
|
||||||
|
_TabletForgotPasswordOtpPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TabletForgotPasswordOtpPageState
|
||||||
|
extends State<TabletForgotPasswordOtpPage> {
|
||||||
|
late final AuthViewModel viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
viewModel = context.read<AuthViewModel>();
|
||||||
|
viewModel.addListener(_viewModelListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _viewModelListener() {
|
||||||
|
if (viewModel.errorMessageOtp != null) {
|
||||||
|
AppToast.error(context, viewModel.errorMessageOtp!);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewModel.resetToken != null) {
|
||||||
|
Router.neglect(
|
||||||
|
context,
|
||||||
|
() => Navigator.push(
|
||||||
|
context,
|
||||||
|
MaterialPageRoute(builder: (_) => const ForgotPasswordCreateScreen()),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
viewModel.removeListener(_viewModelListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -26,7 +66,6 @@ class TabletForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
return Center(
|
return Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 364,
|
width: 364,
|
||||||
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -62,9 +101,6 @@ class TabletForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
controller: viewModel.otpController,
|
controller: viewModel.otpController,
|
||||||
length: 5,
|
length: 5,
|
||||||
pinAnimationType: PinAnimationType.scale,
|
pinAnimationType: PinAnimationType.scale,
|
||||||
onCompleted: (value) {
|
|
||||||
debugPrint('OTP: $value');
|
|
||||||
},
|
|
||||||
defaultPinTheme: PinTheme(
|
defaultPinTheme: PinTheme(
|
||||||
width: 50.0.w(),
|
width: 50.0.w(),
|
||||||
height: 50.0.h(),
|
height: 50.0.h(),
|
||||||
@@ -80,7 +116,7 @@ class TabletForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
SizedBox(height: 24.0.h()),
|
SizedBox(height: 24.0.h()),
|
||||||
viewModel.isLoading
|
viewModel.isLoadingOtp
|
||||||
? const BaseButton(
|
? const BaseButton(
|
||||||
isEnabled: false,
|
isEnabled: false,
|
||||||
text: ForgotPasswordOtpStrings.resetLink,
|
text: ForgotPasswordOtpStrings.resetLink,
|
||||||
@@ -89,15 +125,13 @@ class TabletForgotPasswordOtpPage extends StatelessWidget {
|
|||||||
: BaseButton(
|
: BaseButton(
|
||||||
isEnabled: viewModel.canSubmitOtpPage,
|
isEnabled: viewModel.canSubmitOtpPage,
|
||||||
text: ForgotPasswordOtpStrings.resetLink,
|
text: ForgotPasswordOtpStrings.resetLink,
|
||||||
onPressed:
|
onPressed: viewModel.canSubmitOtpPage
|
||||||
viewModel.canSubmitOtpPage
|
|
||||||
? () async {
|
? () async {
|
||||||
await viewModel.verifyOtp(context);
|
await viewModel.verifyOtp(context);
|
||||||
}
|
}
|
||||||
: null,
|
: null,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 12.0),
|
const SizedBox(height: 12.0),
|
||||||
|
|
||||||
TextButton(
|
TextButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
context.pop();
|
context.pop();
|
||||||
|
|||||||
@@ -12,9 +12,43 @@ import '../../login/widgets/login_textfield.dart';
|
|||||||
import '../../shared/base_button.dart';
|
import '../../shared/base_button.dart';
|
||||||
import '../strings/forgot_password_strings.dart';
|
import '../strings/forgot_password_strings.dart';
|
||||||
|
|
||||||
class DesktopForgotPasswordPage extends StatelessWidget {
|
class DesktopForgotPasswordPage extends StatefulWidget {
|
||||||
const DesktopForgotPasswordPage({super.key});
|
const DesktopForgotPasswordPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<DesktopForgotPasswordPage> createState() =>
|
||||||
|
_DesktopForgotPasswordPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _DesktopForgotPasswordPageState extends State<DesktopForgotPasswordPage> {
|
||||||
|
late final AuthViewModel viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
viewModel = context.read<AuthViewModel>();
|
||||||
|
viewModel.addListener(_viewModelListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _viewModelListener() {
|
||||||
|
if (viewModel.successMessage != null) {
|
||||||
|
AppToast.success(context, viewModel.successMessage!);
|
||||||
|
const ForgotPasswordOtpRouteData().push(context);
|
||||||
|
viewModel.clearMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewModel.errorMessageForget != null) {
|
||||||
|
AppToast.error(context, viewModel.errorMessageForget!);
|
||||||
|
viewModel.clearMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
viewModel.removeListener(_viewModelListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -22,17 +56,6 @@ class DesktopForgotPasswordPage extends StatelessWidget {
|
|||||||
body: Center(
|
body: Center(
|
||||||
child: Consumer<AuthViewModel>(
|
child: Consumer<AuthViewModel>(
|
||||||
builder: (context, viewModel, _) {
|
builder: (context, viewModel, _) {
|
||||||
if (viewModel.successMessage != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
AppToast.success(context, viewModel.successMessage!);
|
|
||||||
const ForgotPasswordOtpRouteData().push(context);
|
|
||||||
});
|
|
||||||
} else if (viewModel.errorMessage != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
AppToast.error(context, viewModel.errorMessage!);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Row(
|
return Row(
|
||||||
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
mainAxisAlignment: MainAxisAlignment.spaceAround,
|
||||||
children: [
|
children: [
|
||||||
@@ -78,7 +101,7 @@ class DesktopForgotPasswordPage extends StatelessWidget {
|
|||||||
isPassword: false,
|
isPassword: false,
|
||||||
),
|
),
|
||||||
SizedBox(height: 70.0.h()),
|
SizedBox(height: 70.0.h()),
|
||||||
viewModel.isLoading
|
viewModel.isLoadingForgot
|
||||||
? const BaseButton(
|
? const BaseButton(
|
||||||
isEnabled: false,
|
isEnabled: false,
|
||||||
text: ForgotPasswordStrings.resetLink,
|
text: ForgotPasswordStrings.resetLink,
|
||||||
@@ -87,8 +110,7 @@ class DesktopForgotPasswordPage extends StatelessWidget {
|
|||||||
: BaseButton(
|
: BaseButton(
|
||||||
isEnabled: viewModel.isEmailValid,
|
isEnabled: viewModel.isEmailValid,
|
||||||
text: ForgotPasswordStrings.resetLink,
|
text: ForgotPasswordStrings.resetLink,
|
||||||
onPressed:
|
onPressed: viewModel.isEmailValid
|
||||||
viewModel.isEmailValid
|
|
||||||
? () async {
|
? () async {
|
||||||
await viewModel.forgotPassword(context);
|
await viewModel.forgotPassword(context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,9 +12,43 @@ import '../../login/widgets/login_textfield.dart';
|
|||||||
import '../../shared/base_button.dart';
|
import '../../shared/base_button.dart';
|
||||||
import '../strings/forgot_password_strings.dart';
|
import '../strings/forgot_password_strings.dart';
|
||||||
|
|
||||||
class MobileForgotPasswordPage extends StatelessWidget {
|
class MobileForgotPasswordPage extends StatefulWidget {
|
||||||
const MobileForgotPasswordPage({super.key});
|
const MobileForgotPasswordPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<MobileForgotPasswordPage> createState() =>
|
||||||
|
_MobileForgotPasswordPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _MobileForgotPasswordPageState extends State<MobileForgotPasswordPage> {
|
||||||
|
late final AuthViewModel viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
viewModel = context.read<AuthViewModel>();
|
||||||
|
viewModel.addListener(_viewModelListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _viewModelListener() {
|
||||||
|
if (viewModel.successMessage != null) {
|
||||||
|
AppToast.success(context, viewModel.successMessage!);
|
||||||
|
const ForgotPasswordOtpRouteData().push(context);
|
||||||
|
viewModel.clearMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewModel.errorMessageForget != null) {
|
||||||
|
AppToast.error(context, viewModel.errorMessageForget!);
|
||||||
|
viewModel.clearMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
viewModel.removeListener(_viewModelListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
@@ -24,17 +58,6 @@ class MobileForgotPasswordPage extends StatelessWidget {
|
|||||||
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
|
padding: EdgeInsets.symmetric(horizontal: 24.0.w()),
|
||||||
child: Consumer<AuthViewModel>(
|
child: Consumer<AuthViewModel>(
|
||||||
builder: (context, viewModel, _) {
|
builder: (context, viewModel, _) {
|
||||||
if (viewModel.successMessage != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
AppToast.success(context, viewModel.successMessage!);
|
|
||||||
const ForgotPasswordOtpRouteData().push(context);
|
|
||||||
});
|
|
||||||
} else if (viewModel.errorMessage != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
AppToast.error(context, viewModel.errorMessage!);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Column(
|
return Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -73,7 +96,7 @@ class MobileForgotPasswordPage extends StatelessWidget {
|
|||||||
isPassword: false,
|
isPassword: false,
|
||||||
),
|
),
|
||||||
SizedBox(height: 24.0.h()),
|
SizedBox(height: 24.0.h()),
|
||||||
viewModel.isLoading
|
viewModel.isLoadingForgot
|
||||||
? const BaseButton(
|
? const BaseButton(
|
||||||
isEnabled: false,
|
isEnabled: false,
|
||||||
text: ForgotPasswordStrings.resetLink,
|
text: ForgotPasswordStrings.resetLink,
|
||||||
@@ -82,8 +105,7 @@ class MobileForgotPasswordPage extends StatelessWidget {
|
|||||||
: BaseButton(
|
: BaseButton(
|
||||||
isEnabled: viewModel.isEmailValid,
|
isEnabled: viewModel.isEmailValid,
|
||||||
text: ForgotPasswordStrings.resetLink,
|
text: ForgotPasswordStrings.resetLink,
|
||||||
onPressed:
|
onPressed: viewModel.isEmailValid
|
||||||
viewModel.isEmailValid
|
|
||||||
? () async {
|
? () async {
|
||||||
await viewModel.forgotPassword(context);
|
await viewModel.forgotPassword(context);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,25 +12,48 @@ import '../../login/widgets/login_textfield.dart';
|
|||||||
import '../../shared/base_button.dart';
|
import '../../shared/base_button.dart';
|
||||||
import '../strings/forgot_password_strings.dart';
|
import '../strings/forgot_password_strings.dart';
|
||||||
|
|
||||||
class TabletForgotPasswordPage extends StatelessWidget {
|
class TabletForgotPasswordPage extends StatefulWidget {
|
||||||
const TabletForgotPasswordPage({super.key});
|
const TabletForgotPasswordPage({super.key});
|
||||||
|
|
||||||
|
@override
|
||||||
|
State<TabletForgotPasswordPage> createState() =>
|
||||||
|
_TabletForgotPasswordPageState();
|
||||||
|
}
|
||||||
|
|
||||||
|
class _TabletForgotPasswordPageState extends State<TabletForgotPasswordPage> {
|
||||||
|
late final AuthViewModel viewModel;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
super.initState();
|
||||||
|
viewModel = context.read<AuthViewModel>();
|
||||||
|
viewModel.addListener(_viewModelListener);
|
||||||
|
}
|
||||||
|
|
||||||
|
void _viewModelListener() {
|
||||||
|
if (viewModel.successMessage != null) {
|
||||||
|
AppToast.success(context, viewModel.successMessage!);
|
||||||
|
const ForgotPasswordOtpRouteData().push(context);
|
||||||
|
viewModel.clearMessages();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (viewModel.errorMessageForget != null) {
|
||||||
|
AppToast.error(context, viewModel.errorMessageForget!);
|
||||||
|
viewModel.clearMessages();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void dispose() {
|
||||||
|
viewModel.removeListener(_viewModelListener);
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
body: Consumer<AuthViewModel>(
|
body: Consumer<AuthViewModel>(
|
||||||
builder: (context, viewModel, _) {
|
builder: (context, viewModel, _) {
|
||||||
if (viewModel.successMessage != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
AppToast.success(context, viewModel.successMessage!);
|
|
||||||
const ForgotPasswordOtpRouteData().push(context);
|
|
||||||
});
|
|
||||||
} else if (viewModel.errorMessage != null) {
|
|
||||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
||||||
AppToast.error(context, viewModel.errorMessage!);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
return Center(
|
return Center(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: 364,
|
width: 364,
|
||||||
@@ -72,7 +95,7 @@ class TabletForgotPasswordPage extends StatelessWidget {
|
|||||||
isPassword: false,
|
isPassword: false,
|
||||||
),
|
),
|
||||||
SizedBox(height: 24.0.h()),
|
SizedBox(height: 24.0.h()),
|
||||||
viewModel.isLoading
|
viewModel.isLoadingForgot
|
||||||
? const BaseButton(
|
? const BaseButton(
|
||||||
isEnabled: false,
|
isEnabled: false,
|
||||||
text: ForgotPasswordStrings.resetLink,
|
text: ForgotPasswordStrings.resetLink,
|
||||||
@@ -81,8 +104,7 @@ class TabletForgotPasswordPage extends StatelessWidget {
|
|||||||
: BaseButton(
|
: BaseButton(
|
||||||
isEnabled: viewModel.isEmailValid,
|
isEnabled: viewModel.isEmailValid,
|
||||||
text: ForgotPasswordStrings.resetLink,
|
text: ForgotPasswordStrings.resetLink,
|
||||||
onPressed:
|
onPressed: viewModel.isEmailValid
|
||||||
viewModel.isEmailValid
|
|
||||||
? () async {
|
? () async {
|
||||||
await viewModel.forgotPassword(context);
|
await viewModel.forgotPassword(context);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user