login bug fix

This commit is contained in:
Surendiran 2025-09-17 12:08:08 +05:30
parent 264d9d68a2
commit 3a32ef0f6f
3 changed files with 99 additions and 133 deletions

File diff suppressed because one or more lines are too long

View File

@ -193,15 +193,10 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
// // final managerId = ref.watch(managerIdProvider);
// }
Future<void> sendMobileOrEmailVerify(loginUser) async {
Future<bool> sendMobileOrEmailVerify(String loginUser) async {
// await Future.delayed(const Duration(seconds: 5));
try {
if (_formKey.currentState!.validate()) {
// setState(() {
// _isLoading = true;
// });
print('klvbnksdbkjb');
print(Env.apiUrl);
String apiEndpoint;
if (loginUser == 'agent') {
apiEndpoint = switcherStatus == 1
@ -213,8 +208,6 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
: Env.apiUrl + 'auth/verifyStaffWithEmailId';
}
// Determine the API and the payload based on the visible field
Map<String, dynamic> payload = switcherStatus == 1
? {'mobile': _PhoneNumberController.text}
: {'email': _emailController.text};
@ -229,48 +222,42 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
);
if (response.statusCode == 200) {
Map<String, dynamic> data = json.decode(response.body);
bool verificationAgentOrStaff;
if (loginUser == 'agent') {
verificationAgentOrStaff = data['data']['agent_verification'];
} else {
verificationAgentOrStaff = data['data']['Staff_verification'];
}
String message = data['data']['message'];
if (verificationAgentOrStaff) {
final data = json.decode(response.body);
final verification = loginUser == 'agent'
? data['data']['agent_verification']
: data['data']['Staff_verification'];
final message = data['data']['message'];
if (verification == true) {
if (switcherStatus == 1) {
_verifyPhoneNumber();
} else {
setState(() {
enteredEmailOrMobile = true;
});
print('email');
ToastHelper.showSuccessToast(context, 'OTP sent successfully');
}
return true; // success
} else {
// setState(() {
// _isLoading = false;
// });
ToastHelper.showErrorToast(context, message);
print('Invalid mobile number');
return false; // fail
}
} else {
// setState(() {
// _isLoading = false;
// });
ToastHelper.showErrorToast(context, 'Something went wrong');
throw Exception('Failed to verify mobile number');
return false; // fail
}
}
return false;
} catch (e) {
setState(() {
_isLoading = false;
});
ToastHelper.showErrorToast(context, 'Something went wrong');
print('Error: $e');
return false;
}
}
Future<void> verifyMobileOrMailOTP(otpVerifyStatus) async {
try {
// Select API endpoint
@ -317,7 +304,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
print('userRole -- $userRole');
context.go(AppRoutes.dashboard);
} else {
ToastHelper.showWarningToast(
ToastHelper.showErrorToast(
context,
data['message'] ?? 'Invalid OTP',
);
@ -338,7 +325,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
}
}
void verifyFirebaseMobileOTP() async {
Future<void> verifyFirebaseMobileOTP() async {
try {
// setState(() {
// _isLoading = true;
@ -363,7 +350,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
if (userCredential.user != null) {
print('otp firebase check done');
bool otpVerifyStatus = true;
verifyMobileOrMailOTP(otpVerifyStatus);
await verifyMobileOrMailOTP(otpVerifyStatus);
} else {
ToastHelper.showErrorToast(context, 'Invalid OTP. Please try again.');
}
@ -935,11 +922,19 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
text: "Login as Agent",
backgroundColor: Color(0xFF436462),
onPressed: () async {
sendMobileOrEmailVerify('agent');
setState(() {
clickedButtonName = 'agent';
});
await Future.delayed(const Duration(seconds: 5));
// Wait for API to finish
final success = await sendMobileOrEmailVerify('agent');
if (success) {
// API success loader stops immediately
print("✅ API success");
} else {
// API failed loader also stops immediately
print("❌ API failed");
}
},
),
// ElevatedButton(
@ -993,11 +988,20 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
text: "Login as Staff",
backgroundColor: Color(0xFF436462),
onPressed: () async {
sendMobileOrEmailVerify('staff');
setState(() {
clickedButtonName = 'staff';
});
await Future.delayed(const Duration(seconds: 5));
// Wait for API to finish
final success = await sendMobileOrEmailVerify('staff');
if (success) {
// API success loader stops immediately
print("✅ API success");
} else {
// API failed loader also stops immediately
print("❌ API failed");
}
},
),
// ElevatedButton(
@ -1116,7 +1120,7 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
// ],
AnimatedSwitcher(
duration: const Duration(
milliseconds: 1000,
milliseconds: 500,
), // animation speed
switchInCurve: Curves.easeInOutCirc,
switchOutCurve: Curves.easeOutCirc,
@ -1195,13 +1199,10 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
backgroundColor: Color(0xFF436462),
onPressed: () async {
if (switcherStatus == 1) {
verifyFirebaseMobileOTP();
await verifyFirebaseMobileOTP();
} else {
verifyMobileOrMailOTP(_otpController.text);
await verifyMobileOrMailOTP(_otpController.text);
}
await Future.delayed(
const Duration(seconds: 5),
);
},
),
// ElevatedButton(
@ -1252,14 +1253,14 @@ class _LoginScreenState extends ConsumerState<LoginScreen> {
onTap: () {
setState(() {
selectedIndex = index + 1;
enteredEmailOrMobile = false;
_PhoneNumberController.text = '';
_emailController.text = '';
_otpController.text = '';
if (selectedIndex == 2) {
switcherStatus = 0;
_PhoneNumberController.text = '';
enteredEmailOrMobile = false;
} else {
switcherStatus = 1;
_emailController.text = '';
enteredEmailOrMobile = false;
}
});
},

View File

@ -5,10 +5,10 @@ packages:
dependency: transitive
description:
name: _fe_analyzer_shared
sha256: da0d9209ca76bde579f2da330aeb9df62b6319c834fa7baae052021b0462401f
sha256: f0bb5d1648339c8308cc0b9838d8456b3cfe5c91f9dc1a735b4d003269e5da9a
url: "https://pub.dev"
source: hosted
version: "85.0.0"
version: "88.0.0"
_flutterfire_internals:
dependency: transitive
description:
@ -21,10 +21,10 @@ packages:
dependency: transitive
description:
name: analyzer
sha256: "974859dc0ff5f37bc4313244b3218c791810d03ab3470a579580279ba971a48d"
sha256: "0b7b9c329d2879f8f05d6c05b32ee9ec025f39b077864bdb5ac9a7b63418a98f"
url: "https://pub.dev"
source: hosted
version: "7.7.1"
version: "8.1.1"
animated_bottom_navigation_bar:
dependency: "direct main"
description:
@ -69,18 +69,18 @@ packages:
dependency: transitive
description:
name: build
sha256: "7d95cbbb1526ab5ae977df9b4cc660963b9b27f6d1075c0b34653868911385e4"
sha256: "5b887c55a0f734b433b3b2d89f9cd1f99eb636b17e268a5b4259258bc916504b"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "4.0.0"
build_config:
dependency: transitive
description:
name: build_config
sha256: "4ae2de3e1e67ea270081eaee972e1bd8f027d459f249e0f1186730784c2e7e33"
sha256: "4f64382b97504dc2fcdf487d5aae33418e08b4703fc21249e4db6d804a4d0187"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
version: "1.2.0"
build_daemon:
dependency: transitive
description:
@ -89,30 +89,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.0.4"
build_resolvers:
dependency: transitive
description:
name: build_resolvers
sha256: "38c9c339333a09b090a638849a4c56e70a404c6bdd3b511493addfbc113b60c2"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
build_runner:
dependency: "direct dev"
description:
name: build_runner
sha256: b971d4a1c789eba7be3e6fe6ce5e5b50fd3719e3cb485b3fad6d04358304351d
sha256: "804c47c936df75e1911c19a4fb8c46fa8ff2b3099b9f2b2aa4726af3774f734b"
url: "https://pub.dev"
source: hosted
version: "2.6.0"
build_runner_core:
dependency: transitive
description:
name: build_runner_core
sha256: c04e612ca801cd0928ccdb891c263a2b1391cb27940a5ea5afcf9ba894de5d62
url: "https://pub.dev"
source: hosted
version: "9.2.0"
version: "2.8.0"
built_collection:
dependency: transitive
description:
@ -125,10 +109,10 @@ packages:
dependency: transitive
description:
name: built_value
sha256: ba95c961bafcd8686d1cf63be864eb59447e795e124d98d6a27d91fcd13602fb
sha256: a30f0a0e38671e89a492c44d005b5545b830a961575bbd8336d42869ff71066d
url: "https://pub.dev"
source: hosted
version: "8.11.1"
version: "8.12.0"
characters:
dependency: transitive
description:
@ -165,10 +149,10 @@ packages:
dependency: transitive
description:
name: code_builder
sha256: "0ec10bf4a89e4c613960bf1e8b42c64127021740fb21640c29c909826a5eea3e"
sha256: "11654819532ba94c34de52ff5feb52bd81cba1de00ef2ed622fd50295f9d4243"
url: "https://pub.dev"
source: hosted
version: "4.10.1"
version: "4.11.0"
collection:
dependency: transitive
description:
@ -237,10 +221,10 @@ packages:
dependency: transitive
description:
name: dart_style
sha256: "8a0e5fba27e8ee025d2ffb4ee820b4e6e2cf5e4246a6b1a477eb66866947e0bb"
sha256: c87dfe3d56f183ffe9106a18aebc6db431fc7c98c31a54b952a77f3d54a85697
url: "https://pub.dev"
source: hosted
version: "3.1.1"
version: "3.1.2"
dbus:
dependency: transitive
description:
@ -309,17 +293,10 @@ packages:
dependency: "direct main"
description:
name: file_picker
<<<<<<< HEAD
sha256: e7e16c9d15c36330b94ca0e2ad8cb61f93cd5282d0158c09805aed13b5452f22
url: "https://pub.dev"
source: hosted
version: "10.3.2"
=======
sha256: f2d9f173c2c14635cc0e9b14c143c49ef30b4934e8d1d274d6206fcb0086a06f
url: "https://pub.dev"
source: hosted
version: "10.3.3"
>>>>>>> 7094c17 (login issue fix)
firebase_app_check:
dependency: "direct main"
description:
@ -555,10 +532,10 @@ packages:
dependency: "direct main"
description:
name: go_router
sha256: "8b1f37dfaf6e958c6b872322db06f946509433bec3de753c3491a42ae9ec2b48"
sha256: eb059dfe59f08546e9787f895bd01652076f996bcbf485a8609ef990419ad227
url: "https://pub.dev"
source: hosted
version: "16.1.0"
version: "16.2.1"
google_fonts:
dependency: "direct main"
description:
@ -603,10 +580,10 @@ packages:
dependency: transitive
description:
name: google_sign_in_platform_interface
sha256: "8736443134d2cccadd4f228d600177cb3947e36683466a6ab96877ce6932885a"
sha256: "7f59208c42b415a3cca203571128d6f84f885fead2d5b53eb65a9e27f2965bb5"
url: "https://pub.dev"
source: hosted
version: "3.0.0"
version: "3.1.0"
google_sign_in_web:
dependency: transitive
description:
@ -699,10 +676,10 @@ packages:
dependency: "direct dev"
description:
name: json_serializable
sha256: ce2cf974ccdee13be2a510832d7fba0b94b364e0b0395dee42abaa51b855be27
sha256: "33a040668b31b320aafa4822b7b1e177e163fc3c1e835c6750319d4ab23aa6fe"
url: "https://pub.dev"
source: hosted
version: "6.10.0"
version: "6.11.1"
jwt_decode:
dependency: "direct main"
description:
@ -715,10 +692,10 @@ packages:
dependency: transitive
description:
name: leak_tracker
sha256: "8dcda04c3fc16c14f48a7bb586d4be1f0d1572731b6d81d51772ef47c02081e0"
sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de"
url: "https://pub.dev"
source: hosted
version: "11.0.1"
version: "11.0.2"
leak_tracker_flutter_testing:
dependency: transitive
description:
@ -755,10 +732,10 @@ packages:
dependency: transitive
description:
name: local_auth_android
sha256: "48924f4a8b3cc45994ad5993e2e232d3b00788a305c1bf1c7db32cef281ce9a3"
sha256: "1ee0e63fb8b5c6fa286796b5fb1570d256857c2f4a262127e728b36b80a570cf"
url: "https://pub.dev"
source: hosted
version: "1.0.52"
version: "1.0.53"
local_auth_darwin:
dependency: transitive
description:
@ -955,18 +932,18 @@ packages:
dependency: transitive
description:
name: path_provider_android
sha256: d0d310befe2c8ab9e7f393288ccbb11b60c019c6b5afc21973eeee4dda2b35e9
sha256: "993381400e94d18469750e5b9dcb8206f15bc09f9da86b9e44a9b0092a0066db"
url: "https://pub.dev"
source: hosted
version: "2.2.17"
version: "2.2.18"
path_provider_foundation:
dependency: transitive
description:
name: path_provider_foundation
sha256: "4843174df4d288f5e29185bd6e72a6fbdf5a4a4602717eed565497429f179942"
sha256: "16eef174aacb07e09c351502740fa6254c165757638eba1e9116b0a781201bbd"
url: "https://pub.dev"
source: hosted
version: "2.4.1"
version: "2.4.2"
path_provider_linux:
dependency: transitive
description:
@ -1003,18 +980,18 @@ packages:
dependency: transitive
description:
name: petitparser
sha256: "07c8f0b1913bcde1ff0d26e57ace2f3012ccbf2b204e070290dad3bb22797646"
sha256: "1a97266a94f7350d30ae522c0af07890c70b8e62c71e8e3920d1db4d23c057d1"
url: "https://pub.dev"
source: hosted
version: "6.1.0"
version: "7.0.1"
pinput:
dependency: "direct main"
description:
name: pinput
sha256: "8a73be426a91fefec90a7f130763ca39772d547e92f19a827cf4aa02e323d35a"
sha256: c41f42ee301505ae2375ec32871c985d3717bf8aee845620465b286e0140aad2
url: "https://pub.dev"
source: hosted
version: "5.0.1"
version: "5.0.2"
platform:
dependency: transitive
description:
@ -1091,10 +1068,10 @@ packages:
dependency: transitive
description:
name: shared_preferences_android
sha256: "5bcf0772a761b04f8c6bf814721713de6f3e5d9d89caf8d3fe031b02a342379e"
sha256: a2608114b1ffdcbc9c120eb71a0e207c71da56202852d4aab8a5e30a82269e74
url: "https://pub.dev"
source: hosted
version: "2.4.11"
version: "2.4.12"
shared_preferences_foundation:
dependency: transitive
description:
@ -1160,18 +1137,18 @@ packages:
dependency: transitive
description:
name: source_gen
sha256: "7b19d6ba131c6eb98bfcbf8d56c1a7002eba438af2e7ae6f8398b2b0f4f381e3"
sha256: ccf30b0c9fbcd79d8b6f5bfac23199fb354938436f62475e14aea0f29ee0f800
url: "https://pub.dev"
source: hosted
version: "3.1.0"
version: "4.0.1"
source_helper:
dependency: transitive
description:
name: source_helper
sha256: a447acb083d3a5ef17f983dd36201aeea33fedadb3228fa831f2f0c92f0f3aca
sha256: "6a3c6cc82073a8797f8c4dc4572146114a39652851c157db37e964d9c7038723"
url: "https://pub.dev"
source: hosted
version: "1.3.7"
version: "1.3.8"
source_span:
dependency: transitive
description:
@ -1244,14 +1221,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.7.6"
timing:
dependency: transitive
description:
name: timing
sha256: "62ee18aca144e4a9f29d212f5a4c6a053be252b895ab14b5821996cff4ed90fe"
url: "https://pub.dev"
source: hosted
version: "1.0.2"
toastification:
dependency: "direct main"
description:
@ -1304,10 +1273,10 @@ packages:
dependency: transitive
description:
name: url_launcher_android
sha256: "69ee86740f2847b9a4ba6cffa74ed12ce500bbe2b07f3dc1e643439da60637b7"
sha256: "07cffecb7d68cbc6437cd803d5f11a86fe06736735c3dfe46ff73bcb0f958eed"
url: "https://pub.dev"
source: hosted
version: "6.3.18"
version: "6.3.21"
url_launcher_ios:
dependency: transitive
description:
@ -1376,18 +1345,18 @@ packages:
dependency: transitive
description:
name: vm_service
sha256: ddfa8d30d89985b96407efce8acbdd124701f96741f2d981ca860662f1c0dc02
sha256: "45caa6c5917fa127b5dbcfbd1fa60b14e583afdc08bfc96dda38886ca252eb60"
url: "https://pub.dev"
source: hosted
version: "15.0.0"
version: "15.0.2"
watcher:
dependency: transitive
description:
name: watcher
sha256: "0b7fd4a0bbc4b92641dbf20adfd7e3fd1398fe17102d94b674234563e110088a"
sha256: "5bf046f41320ac97a469d506261797f35254fa61c641741ef32dacda98b7d39c"
url: "https://pub.dev"
source: hosted
version: "1.1.2"
version: "1.1.3"
web:
dependency: transitive
description:
@ -1432,10 +1401,10 @@ packages:
dependency: transitive
description:
name: xml
sha256: b015a8ad1c488f66851d762d3090a21c600e479dc75e68328c52774040cf9226
sha256: "971043b3a0d3da28727e40ed3e0b5d18b742fa5a68665cca88e74b7876d5e025"
url: "https://pub.dev"
source: hosted
version: "6.5.0"
version: "6.6.1"
yaml:
dependency: transitive
description:
@ -1445,5 +1414,5 @@ packages:
source: hosted
version: "3.1.3"
sdks:
dart: ">=3.8.1 <4.0.0"
flutter: ">=3.32.0"
dart: ">=3.9.0 <4.0.0"
flutter: ">=3.35.0"