diff --git a/lib/pages/login/saved_login.dart b/lib/pages/login/saved_login.dart index 327c2a43..e919d418 100644 --- a/lib/pages/login/saved_login.dart +++ b/lib/pages/login/saved_login.dart @@ -15,6 +15,7 @@ import 'package:hmg_patient_app/models/Authentication/check_paitent_authenticati import 'package:hmg_patient_app/models/Authentication/select_device_imei_res.dart'; import 'package:hmg_patient_app/models/InPatientServices/get_admission_info_response_model.dart'; import 'package:hmg_patient_app/models/InPatientServices/get_admission_request_info_response_model.dart'; +import 'package:hmg_patient_app/new_ui/new_ext.dart'; import 'package:hmg_patient_app/new_ui/otp/otp_validation_bootmsheet_widget.dart'; import 'package:hmg_patient_app/pages/landing/landing_page.dart'; import 'package:hmg_patient_app/pages/login/register_new.dart'; @@ -37,6 +38,7 @@ import 'package:hmg_patient_app/widgets/transitions/fade_page.dart'; import 'package:local_auth/local_auth.dart'; import 'package:provider/provider.dart'; +import '../../new_ui/exception_widget/ExceptionBottomSheet.dart'; import '../../widgets/dialogs/confirm_dialog.dart'; class SavedLogin extends StatefulWidget { @@ -330,7 +332,14 @@ class _SavedLogin extends State { ); } on PlatformException catch (e) { GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: 'Please enable your Touch or Face ID'); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: "Please enable your Touch or Face ID", + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }), + ); return; } @@ -369,19 +378,29 @@ class _SavedLogin extends State { // this.patientOutSA = result['PatientOutSA']; // setDefault(); sharedPref.setInt(LAST_LOGIN, lastLogin); - checkActivationCode(null, lastLogin, result['LogInTokenID']); + checkActivationCode(null, lastLogin, result['LogInTokenID'], onWrongActivationCode: (String? message) {}); } else if (result['ErrorEndUserMessage'] != null) { - ConfirmDialog dialog = new ConfirmDialog( - context: context, - confirmMessage: result['ErrorEndUserMessage'], - okText: TranslationBase.of(context).confirm, - cancelText: TranslationBase.of(context).cancel_nocaps, - okFunction: () => { - ConfirmDialog.closeAlertDialog(context), - Navigator.of(context).pushReplacement(FadePage(page: WelcomeLogin())), - }, - cancelFunction: () => {}); - dialog.showAlertDialog(context); + GifLoaderDialogUtils.hideDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result['ErrorEndUserMessage'], + showCancel: true, + onOkPressed: () { + Navigator.of(context).pop(); + Navigator.of(context).pushReplacement(FadePage(page: WelcomeLogin())); + }), + ); + // ConfirmDialog dialog = new ConfirmDialog( + // context: context, + // confirmMessage: result['ErrorEndUserMessage'], + // okText: TranslationBase.of(context).confirm, + // cancelText: TranslationBase.of(context).cancel_nocaps, + // okFunction: () => { + // ConfirmDialog.closeAlertDialog(context), + // Navigator.of(context).pushReplacement(FadePage(page: WelcomeLogin())), + // }, + // cancelFunction: () => {}); + // dialog.showAlertDialog(context); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); @@ -389,7 +408,7 @@ class _SavedLogin extends State { }); } - checkActivationCode(String? value, int loginType, String? loginToken) async { + checkActivationCode(String? value, int loginType, String? loginToken, {required Function(String? message) onWrongActivationCode}) async { AppGlobal.context = context; GifLoaderDialogUtils.showMyDialog(context); var request = authService @@ -416,10 +435,11 @@ class _SavedLogin extends State { { //699 block run here GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 2), () { - AppToast.showErrorToast(message: result.errorEndUserMessage); - Navigator.pop(context); - }) + onWrongActivationCode(result.errorEndUserMessage), + // Future.delayed(Duration(seconds: 2), () { + // AppToast.showErrorToast(message: result.errorEndUserMessage); + // Navigator.pop(context); + // }) } else { @@ -443,9 +463,10 @@ class _SavedLogin extends State { { // Navigator.of(context).pop(), GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 1), () { - AppToast.showErrorToast(message: result, localContext: context); - }), + onWrongActivationCode(result), + // Future.delayed(Duration(seconds: 1), () { + // AppToast.showErrorToast(message: result, localContext: context); + // }), projectViewModel.analytics.loginRegistration.login_fail(error: result), projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result) } @@ -576,7 +597,7 @@ class _SavedLogin extends State { else { if (value['IsAuthenticated']) - {this.checkActivationCode(null, type, value['LogInTokenID'])} + {this.checkActivationCode(null, type, value['LogInTokenID'], onWrongActivationCode: (String? message) {})} else { AppToast.showErrorToast(message: value['errorMessage']), @@ -592,17 +613,27 @@ class _SavedLogin extends State { .catchError((err) { print(err); GifLoaderDialogUtils.hideDialog(context); - ConfirmDialog dialog = new ConfirmDialog( - context: context, - confirmMessage: err, - okText: TranslationBase.of(context).confirm, - cancelText: TranslationBase.of(context).cancel_nocaps, - okFunction: () => { - ConfirmDialog.closeAlertDialog(context), - Navigator.of(context).push(FadePage(page: RegisterNew())), - }, - cancelFunction: () => {}); - dialog.showAlertDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err, + showCancel: true, + onOkPressed: () { + Navigator.of(context).pop(); + Navigator.of(context).pushReplacement(FadePage(page: RegisterNew())); + }), + ); + + // ConfirmDialog dialog = new ConfirmDialog( + // context: context, + // confirmMessage: err, + // okText: TranslationBase.of(context).confirm, + // cancelText: TranslationBase.of(context).cancel_nocaps, + // okFunction: () => { + // ConfirmDialog.closeAlertDialog(context), + // Navigator.of(context).push(FadePage(page: RegisterNew())), + // }, + // cancelFunction: () => {}); + // dialog.showAlertDialog(context); projectViewModel.analytics.loginRegistration.login_fail(error: err.toString()); }); } @@ -631,28 +662,20 @@ class _SavedLogin extends State { } }).catchError((r) { GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: r.toString()); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: r, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }), + ); + // AppToast.showErrorToast(message: r.toString()); }); } var tempType; - // - // startSMSService(type, String loginToken) { - // tempType = type; - // SMSOTP( - // context, - // type, - // phoneController.text, - // (value) { - // this.checkActivationCode(value, type, loginToken); - // }, - // () => { - // Navigator.pop(context), - // }, - // ).displayDialog(context); - // } - startSMSService(type, String loginToken) { tempType = type; late SMSOTP smsOtp; // Declare the variable first @@ -662,8 +685,17 @@ class _SavedLogin extends State { type, phoneController!.text, (code) { - smsOtp.dispose(); // Now we can reference it - this.checkActivationCode(code, type, loginToken); + checkActivationCode(code, type, loginToken, onWrongActivationCode: (String? message) { + context.showBottomSheet( + child: ExceptionBottomSheet( + message: message.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + // Don't resume timer here, let it continue naturally when user tries again + }, + ), + ); + }); }, () { smsOtp.dispose(); // Now we can reference it