From 5dfa9bafb9e9728f140c5d8be82b000f7bc77df8 Mon Sep 17 00:00:00 2001 From: Aamir Muhammad Date: Thu, 7 Aug 2025 17:01:42 +0300 Subject: [PATCH] Exception Widget & Fixes --- lib/core/service/client/base_app_client.dart | 4 +- .../ExceptionBottomSheet.dart | 123 ++++++ lib/new_ui/new_ext.dart | 13 + lib/pages/login/register_new.dart | 414 ++++++++---------- lib/pages/login/welcome.dart | 385 ++++++++-------- lib/theme/colors.dart | 1 + lib/uitl/utils.dart | 23 +- 7 files changed, 534 insertions(+), 429 deletions(-) create mode 100644 lib/new_ui/exception_widget/ExceptionBottomSheet.dart create mode 100644 lib/new_ui/new_ext.dart diff --git a/lib/core/service/client/base_app_client.dart b/lib/core/service/client/base_app_client.dart index a10c3033..5b6d0bb8 100644 --- a/lib/core/service/client/base_app_client.dart +++ b/lib/core/service/client/base_app_client.dart @@ -187,8 +187,8 @@ class BaseAppClient { // body['IdentificationNo'] = 1023854217; // body['MobileNo'] = "531940021"; //0560717232 - body['PatientID'] = 2266239; //4609100 - body['TokenID'] = "@dm!n"; + // body['PatientID'] = 2266239; //4609100 + // body['TokenID'] = "@dm!n"; // Patient ID: 3027574 // Mobile no.: 0502303285 diff --git a/lib/new_ui/exception_widget/ExceptionBottomSheet.dart b/lib/new_ui/exception_widget/ExceptionBottomSheet.dart new file mode 100644 index 00000000..dc72c42b --- /dev/null +++ b/lib/new_ui/exception_widget/ExceptionBottomSheet.dart @@ -0,0 +1,123 @@ +import 'package:flutter/material.dart'; +import 'package:flutter_svg/svg.dart'; +import 'package:google_fonts/google_fonts.dart'; +import 'package:hmg_patient_app/pages/AlHabibMedicalService/health_calculator/carbs/carbs.dart'; +import 'package:hmg_patient_app/uitl/translations_delegate_base.dart'; +import 'package:hmg_patient_app/uitl/utils.dart'; +import 'package:hmg_patient_app/uitl/font_utils.dart'; +import 'package:hmg_patient_app/widgets/text/app_texts_widget.dart'; + +import '../../theme/colors.dart'; +import '../otp/otp_validation_bootmsheet_widget.dart'; + +class ExceptionBottomSheet extends StatefulWidget { + String message; + bool showOKButton; + bool showCancel; + Function() onOkPressed; + Function()? onCancelPressed; + + ExceptionBottomSheet({Key? key, required this.message, this.showOKButton = true, this.showCancel = false, required this.onOkPressed, this.onCancelPressed}) : super(key: key); + + @override + _ExceptionBottomSheetState createState() => _ExceptionBottomSheetState(); +} + +class _ExceptionBottomSheetState extends State { + @override + void initState() { + super.initState(); + } + + @override + Widget build(BuildContext context) { + return SafeArea( + child: GestureDetector( + onTap: () { + FocusScope.of(context).unfocus(); // Dismiss the keyboard when tapping outside + }, + child: Builder(builder: (context) { + return Directionality( + textDirection: Directionality.of(context), + child: Container( + padding: const EdgeInsets.all(24), + decoration: BoxDecoration( + color: Color(0xFFF8F8FA), + borderRadius: const BorderRadius.vertical(top: Radius.circular(16)), + ), + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.stretch, + children: [ + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + AppText("Error", fontSize: 28, letterSpacing: -2, color: Color(0xFF2E3039), fontWeight: FontWeight.w600), + InkWell( + onTap: () { + Navigator.of(context).pop(); + }, + child: SvgPicture.asset("assets/images/svg/cross-circle.svg", width: 24, height: 24)), + ], + ), + const SizedBox(height: 10), + AppText(widget.message ?? "", fontSize: 16, color: Color(0xFF2E3039), fontWeight: FontWeight.w500), + const SizedBox(height: 10), + SizedBox(height: 24), + if (widget.showOKButton && widget.showCancel) + Row( + children: [ + Expanded( + child: Padding( + padding: const EdgeInsets.only(right: 8), + child: CustomButton( + text: TranslationBase.of(context).cancel, + onPressed: widget.onCancelPressed != null + ? widget.onCancelPressed! + : () { + Navigator.of(context).pop(); + }, + backgroundColor: CustomColors.bgRedLightColor, + borderColor: CustomColors.bgRedLightColor, + textColor: CustomColors.bgRedColor, + icon: "assets/images/svg/cancel.svg", + ), + ), + ), + SizedBox( + width: 16, + ), + Expanded( + child: CustomButton( + text: TranslationBase.of(context).ok, + onPressed: widget.onOkPressed, + backgroundColor: CustomColors.bgRedColor, + borderColor: CustomColors.bgRedBorderColor, + textColor: Colors.white, + icon: "assets/images/svg/confirm.svg", + ), + ), + ], + ), + if (widget.showOKButton && !widget.showCancel) + Padding( + padding: const EdgeInsets.only(bottom: 10), + child: CustomButton( + text: TranslationBase.of(context).ok, + onPressed: widget.onOkPressed, + backgroundColor: CustomColors.bgRedColor, + borderColor: CustomColors.bgRedBorderColor, + textColor: Colors.white, + icon: "assets/images/svg/confirm.svg", + ), + ), + ], + ), + ), + ); + }), + ), + ); + } +} diff --git a/lib/new_ui/new_ext.dart b/lib/new_ui/new_ext.dart new file mode 100644 index 00000000..1df7bb09 --- /dev/null +++ b/lib/new_ui/new_ext.dart @@ -0,0 +1,13 @@ +import 'package:flutter/material.dart'; + +extension ShowBottomSheet on BuildContext { + Future showBottomSheet({required Widget child}) { + return showModalBottomSheet( + context: this, + isScrollControlled: true, + isDismissible: false, + backgroundColor: Colors.transparent, + builder: (_) => child, + ); + } +} diff --git a/lib/pages/login/register_new.dart b/lib/pages/login/register_new.dart index 3f2ff485..be30b7f8 100644 --- a/lib/pages/login/register_new.dart +++ b/lib/pages/login/register_new.dart @@ -16,6 +16,7 @@ import 'package:hmg_patient_app/models/Authentication/check_user_status_req.dart import 'package:hmg_patient_app/models/Authentication/checkpatient_for_registration.dart'; import 'package:hmg_patient_app/models/Authentication/register_info_response.dart'; import 'package:hmg_patient_app/models/Authentication/send_activation_request.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/AlHabibMedicalService/health_calculator/carbs/carbs.dart'; import 'package:hmg_patient_app/pages/login/login-type.dart'; @@ -46,6 +47,7 @@ import '../../models/Authentication/authenticated_user.dart'; import '../../models/Authentication/select_device_imei_res.dart'; import '../../models/InPatientServices/get_admission_info_response_model.dart'; import '../../models/InPatientServices/get_admission_request_info_response_model.dart'; +import '../../new_ui/exception_widget/ExceptionBottomSheet.dart'; import '../../services/clinic_services/get_clinic_service.dart'; import '../../widgets/dialogs/alert_dialog.dart'; import '../../widgets/dialogs/confirm_dialog.dart'; @@ -306,28 +308,60 @@ class _RegisterNew extends State { icon: "assets/images/svg/note-edit.svg", onPressed: () { // bool isValid = Utils.validateIqama(nationalIDorFile.text); - if (nationalIDorFile == null) { - Utils.showErrorToast(TranslationBase.of(context).pleaseEnterNationalId); + if (nationalIDorFile == null || nationalIDorFile.text.isEmpty) { + context.showBottomSheet( + child: ExceptionBottomSheet( + message: TranslationBase.of(context).pleaseEnterNationalId, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + // Utils.showErrorToast(TranslationBase.of(context).pleaseEnterNationalId); return; } - if (selectedCountry == null) { - Utils.showErrorToast(TranslationBase.of(context).pleaseSelectCountry); + if (selectedCountry == null || selectedCountry.countryCode.isEmpty) { + context.showBottomSheet( + child: ExceptionBottomSheet( + message: TranslationBase.of(context).pleaseSelectCountry, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); return; } if (selectedDOB == null) { - Utils.showErrorToast(TranslationBase.of(context).pleaseSelectDOB); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: TranslationBase.of(context).pleaseSelectDOB, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); return; } if (!isTermsAccepted) { - Utils.showErrorToast(TranslationBase.of(context).pleaseAcceptTermsConditions); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: TranslationBase.of(context).pleaseAcceptTermsConditions, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); return; } if (phoneController != null) { phoneController.clear(); } - showModalBottomSheet( context: context, isScrollControlled: true, @@ -349,7 +383,7 @@ class _RegisterNew extends State { child: CustomButton( text: TranslationBase.of(context).sendOTPSMS, onPressed: () { - int? val = Utils.onOtpBtnPressed(OTPType.sms, mobileNo); + int? val = Utils.onOtpBtnPressed(OTPType.sms, mobileNo, context); registerUser(val); }, backgroundColor: CustomColors.bgRedColor, @@ -379,9 +413,8 @@ class _RegisterNew extends State { child: CustomButton( text: TranslationBase.of(context).sendOTPWHATSAPP, onPressed: () { - int? val = Utils.onOtpBtnPressed(OTPType.whatsapp, mobileNo); + int? val = Utils.onOtpBtnPressed(OTPType.whatsapp, mobileNo, context); registerUser(val); - // if (val != null) checkUserAuthentication(val); }, backgroundColor: Colors.white, borderColor: Color(0xFF2E3039), @@ -495,10 +528,6 @@ class _RegisterNew extends State { void registerUser(int? value) { otpType = value == 1 ? OTPType.sms : OTPType.whatsapp; - // OTPType.sms ? 1 : 2; - print("Country: ${selectedCountry.name}"); - print("nationalId: ${nationalIDorFile.text}"); - print("DOB: ${selectedDOB}"); if (value == 1) { print("OTP sent successfully to ${mobileNo} using SMS"); } else { @@ -527,7 +556,7 @@ class _RegisterNew extends State { GifLoaderDialogUtils.showMyDialog(context); authService.checkPatientForRegisteration(registrationData, languageID).then((response) => {checkUserStatus(response, registrationData, type)}).catchError((err) { GifLoaderDialogUtils.hideDialog(context); - ConfirmDialog dialog = new ConfirmDialog( + ConfirmDialog dialog = ConfirmDialog( context: context, confirmMessage: err, okText: TranslationBase.of(context).confirm, @@ -547,21 +576,20 @@ class _RegisterNew extends State { var nRequest = request.toJson(); nRequest['LogInTokenID'] = response['LogInTokenID']; if (response['hasFile'] == true) { - await ConfirmDialog( - context: context, - confirmMessage: response['ErrorEndUserMessage'], - okText: TranslationBase.of(context).ok, - cancelText: TranslationBase.of(context).cancel, - okFunction: () { - AlertDialogBox.closeAlertDialog(context); - sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest); - setState(() { - isSkipRegistration = true; - }); - sendActivationCode(type, "", null, isSkipRegistration); - }, - cancelFunction: () {}) - .showAlertDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: response['ErrorEndUserMessage'], + showCancel: true, + onOkPressed: () { + AlertDialogBox.closeAlertDialog(context); + sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, nRequest); + setState(() { + isSkipRegistration = true; + }); + sendActivationCode(type, "", null, isSkipRegistration); + }, + ), + ); } else { final intl.DateFormat dateFormat = intl.DateFormat('dd/MM/yyyy'); nRequest['forRegister'] = true; @@ -614,7 +642,15 @@ class _RegisterNew extends State { // Navigator.of(context).push(FadePage(page: ConfirmLogin(changePageViewIndex: widget.changePageViewIndex, fromRegistration: true))), sendActivationCode(type, loginToken, resultSet, isSkipRegistration); } else { - AppToast.showErrorToast(message: result != null ? result : TranslationBase.of(context).somethingWentWrong); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result != null ? result : TranslationBase.of(context).somethingWentWrong, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); } }); } @@ -633,6 +669,8 @@ class _RegisterNew extends State { request.isRegister = true; request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!); request.sMSSignature = await SMSOTP.getSignature(); + // print(request.oTPSendType); + // request.oTPSendType = type; GifLoaderDialogUtils.showMyDialog(context); if (selectedCountry.countryCode == "966" && !skipRegistration) { @@ -644,7 +682,7 @@ class _RegisterNew extends State { request.patientIdentificationID = nationalIDorFile.text; } request.isHijri = isHijri ?? 0; - request.oTPSendType = type; + // request.oTPSendType = type; if (skipRegistration) { var req = getCommonRequest(type: type); req.logInTokenID = ""; @@ -667,24 +705,16 @@ class _RegisterNew extends State { } }).catchError((r) { GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: r.toString()); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: r.toString(), + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); }); - - // sendActivationCodeForLogin(type, value['LogInTokenID'], null, false) - // request.loginTokenID = value['LogInTokenID'], - // request.dob = "", - // request.healthId = "", - // request.isHijri = 0, - // request.tokenID = value['LogInTokenID'], - // authService.sendActivationCode(request).then((result) { - // GifLoaderDialogUtils.hideDialog(context); - // if (result != null && result['isSMSSent'] == true) { - // this.startSMSService(type); - // } - // }).catchError((r) { - // GifLoaderDialogUtils.hideDialog(context); - // AppToast.showErrorToast(message: r.toString()); - // }) } else { if (value['IsAuthenticated']) { checkActivationCode(); @@ -693,17 +723,16 @@ class _RegisterNew 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.toString(), + showCancel: true, + onOkPressed: () { + Navigator.of(context).pop(); + Navigator.of(context).push(FadePage(page: RegisterNew())); + }, + ), + ); }); } else { await this.authService.sendActivationCodeRegister(request).then((result) { @@ -715,7 +744,15 @@ class _RegisterNew extends State { } }).catchError((r) { GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: r); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: r.toString(), + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); }); } } @@ -756,10 +793,6 @@ class _RegisterNew extends State { req.patientIdentificationID = nationalIDorFile.text; req.nationalID = nationalIDorFile.text; req.deviceToken = null; - // req.loginType = type; - // req.healthId = ""; - // req.isHijri = isHijri ?? 0; - // req.dob = ""; } try { dynamic result; @@ -769,9 +802,15 @@ class _RegisterNew extends State { final activation = CheckActivationCode.fromJson(result as Map); if (activation.errorCode == '699') { GifLoaderDialogUtils.hideDialog(context); - await Future.delayed(const Duration(seconds: 2)); - AppToast.showErrorToast(message: activation.errorEndUserMessage); - Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin)); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: activation.errorEndUserMessage, + showCancel: false, + onOkPressed: () { + Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin)); + }, + ), + ); } else { await sharedPref.remove(FAMILY_FILE); activation.list!.isFamily = false; @@ -790,9 +829,15 @@ class _RegisterNew extends State { } } else { GifLoaderDialogUtils.hideDialog(context); - await Future.delayed(const Duration(seconds: 1)); - Navigator.of(context).pop(); - AppToast.showErrorToast(message: result, localContext: context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); projectViewModel.analytics.loginRegistration.login_fail(error: result); projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result); } @@ -805,147 +850,33 @@ class _RegisterNew extends State { ); // Optionally: Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); } else { - Navigator.of(context).pop(); GifLoaderDialogUtils.hideDialog(context); - await Future.delayed(const Duration(seconds: 1)); - AppToast.showErrorToast(message: result, localContext: context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); // Optionally: log analytics here } } } catch (err) { GifLoaderDialogUtils.hideDialog(context); - await Future.delayed(const Duration(seconds: 1)); - print(err); - AppToast.showErrorToast(message: err.toString()); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err.toString(), + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); } } - // checkActivationCode({value, type, skipRegistration}) async { - // // Navigator.pop(context); - // // GifLoaderDialogUtils.showMyDialog(context); - // var request = authService.getCommonRequest( - // registerd_data: null, - // deviceToken: DEVICE_TOKEN, - // mobileNumber: int.parse(mobileNo), - // zipCode: selectedCountry.countryCode, - // patientOutSA: selectedCountry.countryCode == "966" ? 0 : 1, - // loginTokenID: LoginTokenID, - // selectedOption: type, - // user: SelectDeviceIMEIRES()); - // dynamic res; - // - // request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!); - // if (selectedCountry.countryCode == "966" && !skipRegistration) { - // request.healthId = nHICData!.healthId!; - // } else { - // request.healthId = ""; - // } - // request.isHijri = isHijri ?? 0; - // if (!skipRegistration) { - // request.nationalID = selectedCountry.countryCode == "966" ? nHICData!.idNumber : nationalIDorFile.text; - // request.patientIdentificationID = selectedCountry.countryCode == "966" ? nHICData!.idNumber : nationalIDorFile.text; - // request.isRegister = true; - // } - // if (skipRegistration) { - // request.patientIdentificationID = nationalIDorFile.text; - // request.nationalID = nationalIDorFile.text; - // request.deviceToken = null; - // request.healthId = ""; - // request.isHijri = isHijri ?? 0; - // request.dob = isHijri == 1 ? selectedDOB!.toString() : dateFormat.format(selectedDOB!); - // authService - // .checkActivationCode(request.toJson(), value) - // .then((result) async => { - // res = result, - // if (result is Map) - // { - // result = CheckActivationCode.fromJson(result as Map), - // if (result.errorCode == '699') - // { - // //699 block run here - // GifLoaderDialogUtils.hideDialog(context), - // Future.delayed(Duration(seconds: 2), () { - // AppToast.showErrorToast(message: result.errorEndUserMessage); - // Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin)); - // }) - // } - // else - // { - // sharedPref.remove(FAMILY_FILE), - // result.list.isFamily = false, - // user = result.list, - // sharedPref.setString(BLOOD_TYPE, result.patientBloodType ?? ""), - // authenticatedUserObject.user = result.list, - // context.read().setPrivilege(privilegeList: res), - // await sharedPref.setObject(MAIN_USER, result.list), - // await sharedPref.setObject(USER_PROFILE, result.list), - // loginTokenID = result.logInTokenID, - // await sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), - // await sharedPref.setString(TOKEN, result.authenticationTokenID), - // checkIfUserAgreedBefore(result, context), - // context.read().analytics.loginRegistration.login_successful(), - // } - // } - // else - // { - // GifLoaderDialogUtils.hideDialog(context), - // Future.delayed(Duration(seconds: 1), () { - // Navigator.of(context).pop(); - // AppToast.showErrorToast(message: result, localContext: context); - // }), - // context.read().analytics.loginRegistration.login_fail(error: result), - // context.read().analytics.errorTracking.log('otp_verification_at_confirm_login', error: result) - // } - // }) - // .catchError((err) { - // GifLoaderDialogUtils.hideDialog(context); - // Future.delayed(Duration(seconds: 1), () { - // print(err); - // AppToast.showErrorToast(message: err); - // // startSMSService(tempType); - // }); - // }); - // } else { - // authService - // .checkActivationCodeRegister(request.toJson(), value) - // .then((result) => { - // res = result, - // if (result is Map) - // { - // result = CheckActivationCode.fromJson(result as Map), - // Navigator.of(context).push( - // FadePage(page: RegisterNewStep2(nHICData, request)), - // ) - // - // // // if(widget.isDubai ==false){ - // // // widget.changePageViewIndex!(1), - // // // if(widget.isDubai ==false){ - // // - // // Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)), - // // } - // } - // else - // { - // Navigator.of(context).pop(), - // GifLoaderDialogUtils.hideDialog(context), - // 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), - // } - // }) - // .catchError((err) { - // print(err); - // GifLoaderDialogUtils.hideDialog(context); - // Future.delayed(Duration(seconds: 1), () { - // AppToast.showErrorToast(message: err); - // // startSMSService(tempType); - // }); - // }); - // } - // } - getCommonRequest({type}) { bool fileNo = false; if (nationalIDorFile.text != null && nationalIDorFile.text.isNotEmpty) { @@ -986,20 +917,6 @@ class _RegisterNew extends State { return request; } - // startSMSService(type) { - // SMSOTP( - // context, - // type, - // phoneController.text, - // (value) { - // this.checkActivationCode(value: value, type: type); - // }, - // () => { - // Navigator.pop(context), - // }, - // ).displayDialog(context); - // } - startSMSService(type, skipRegistration) { late SMSOTP smsOtp; // Declare the variable first smsOtp = SMSOTP( @@ -1007,7 +924,7 @@ class _RegisterNew extends State { type, mobileNo, (code) { - smsOtp.dispose(); // Now we can reference it + smsOtp.dispose(); checkActivationCode(value: code, type: type, skipRegistration: skipRegistration); }, () { @@ -1031,12 +948,16 @@ class _RegisterNew extends State { result = CheckActivationCode.fromJson(result as Map), if (result.errorCode == '699') { - //699 block run here GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 2), () { - AppToast.showErrorToast(message: result.errorEndUserMessage); - Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin)); - }) + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result.errorEndUserMessage, + showCancel: false, + onOkPressed: () { + Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin)); + }, + ), + ), } else { @@ -1058,19 +979,28 @@ class _RegisterNew extends State { else { GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 1), () { - Navigator.of(context).pop(); - AppToast.showErrorToast(message: result, localContext: context); - }), + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result.errorEndUserMessage, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ), } }) .catchError((err) { GifLoaderDialogUtils.hideDialog(context); - Future.delayed(Duration(seconds: 1), () { - print(err); - AppToast.showErrorToast(message: err); - // startSMSService(tempType); - }); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); }); } @@ -1096,12 +1026,28 @@ class _RegisterNew extends State { (r) => false); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); - print(err); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); }); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); - print(err); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err, + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); }); } else { goToHome(context); diff --git a/lib/pages/login/welcome.dart b/lib/pages/login/welcome.dart index 231c4138..d6ba111f 100644 --- a/lib/pages/login/welcome.dart +++ b/lib/pages/login/welcome.dart @@ -14,6 +14,7 @@ import 'package:hmg_patient_app/models/Authentication/select_device_imei_res.dar import 'package:hmg_patient_app/models/Authentication/send_activation_request.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/AlHabibMedicalService/health_calculator/carbs/carbs.dart'; import 'package:hmg_patient_app/pages/landing/landing_page.dart'; @@ -40,6 +41,7 @@ import 'package:intl/src/intl/date_format.dart'; import 'package:provider/provider.dart'; import '../../models/Authentication/authenticated_user.dart'; +import '../../new_ui/exception_widget/ExceptionBottomSheet.dart'; import '../../widgets/dialogs/confirm_dialog.dart'; class WelcomeLogin extends StatefulWidget { @@ -72,7 +74,6 @@ class _WelcomeLogin extends State { var deviceToken; var lastLogin; - AuthenticatedUser? userData; AuthenticatedUserObject authenticatedUserObject = locator(); AppointmentRateViewModel appointmentRateViewModel = locator(); @@ -196,7 +197,7 @@ class _WelcomeLogin extends State { child: SingleChildScrollView( child: GenericBottomSheet( countryCode: selectedCountry.countryCode, - initialPhoneNumber: phoneNumber != null ? phoneNumber :"", + initialPhoneNumber: phoneNumber != null ? phoneNumber : "", textController: phoneController, isEnableCountryDropdown: true, onCountryChange: (value) { @@ -212,7 +213,7 @@ class _WelcomeLogin extends State { child: CustomButton( text: TranslationBase.of(context).sendOTPSMS, onPressed: () { - int? val = Utils.onOtpBtnPressed(OTPType.sms, phoneNumber); + int? val = Utils.onOtpBtnPressed(OTPType.sms, phoneNumber, context); if (val != null) checkUserAuthentication(val); }, backgroundColor: CustomColors.bgRedColor, @@ -241,7 +242,7 @@ class _WelcomeLogin extends State { child: CustomButton( text: TranslationBase.of(context).sendOTPWHATSAPP, onPressed: () { - int? val = Utils.onOtpBtnPressed(OTPType.whatsapp, phoneNumber); + int? val = Utils.onOtpBtnPressed(OTPType.whatsapp, phoneNumber, context); if (val != null) checkUserAuthentication(val); }, backgroundColor: Colors.white, @@ -257,7 +258,16 @@ class _WelcomeLogin extends State { }), ); } else { - Utils.showErrorToast("Please enter National id or File no", context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: "Please enter National id or File no", + showCancel: false, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + // Utils.showErrorToast("Please enter National id or File no", context); } }, ), @@ -314,21 +324,21 @@ class _WelcomeLogin extends State { authService .checkPatientAuthentication(request) .then((value) => { - // GifLoaderDialogUtils.hideDialog(context), - if (value['isSMSSent']) - { - sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), - this.loginTokenID = value['LogInTokenID'], - sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), - // Future.delayed(Duration(seconds: 1), () { - this.sendActivationCode(type) - // }) - } - else - { - if (value['IsAuthenticated']) {this.checkActivationCode()} - } - }) + // GifLoaderDialogUtils.hideDialog(context), + if (value['isSMSSent']) + { + sharedPref.setString(LOGIN_TOKEN_ID, value['LogInTokenID']), + this.loginTokenID = value['LogInTokenID'], + sharedPref.setObject(REGISTER_DATA_FOR_LOGIIN, request), + // Future.delayed(Duration(seconds: 1), () { + this.sendActivationCode(type) + // }) + } + else + { + if (value['IsAuthenticated']) {this.checkActivationCode()} + } + }) .catchError((err) { print(err); GifLoaderDialogUtils.hideDialog(context); @@ -338,9 +348,9 @@ class _WelcomeLogin extends State { okText: TranslationBase.of(context).confirm, cancelText: TranslationBase.of(context).cancel_nocaps, okFunction: () => { - ConfirmDialog.closeAlertDialog(context), - Navigator.of(context).push(FadePage(page: RegisterNew())), - }, + ConfirmDialog.closeAlertDialog(context), + Navigator.of(context).push(FadePage(page: RegisterNew())), + }, cancelFunction: () => {}); dialog.showAlertDialog(context); projectViewModel.analytics.loginRegistration.login_fail(error: err.toString()); @@ -365,7 +375,14 @@ class _WelcomeLogin extends State { } }).catchError((r) { GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: r); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: r.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); + // AppToast.showErrorToast(message: r); }); } else { request.dob = ""; @@ -378,190 +395,167 @@ class _WelcomeLogin extends State { } }).catchError((r) { GifLoaderDialogUtils.hideDialog(context); - AppToast.showErrorToast(message: r.toString()); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: r.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); + // AppToast.showErrorToast(message: r.toString()); }); } } - checkActivationCode({value}) async { - // Navigator.pop(context); + Future checkActivationCode({dynamic value}) async { GifLoaderDialogUtils.showMyDialog(context); - var request = this.getCommonRequest().toJson(); + final request = getCommonRequest().toJson(); dynamic res; - if (healthId != null || isDubai) { - if (isDubai) { - request['DOB'] = dob; - } - request['HealthId'] = healthId; - request['IsHijri'] = isHijri; - - authService - .checkActivationCodeRegister(request, value) - .then((result) => { - res = result, - if (result is Map) - { - result = CheckActivationCode.fromJson(result as Map), - if (this.registerd_data != null && this.registerd_data.isRegister == true) - { - // if(widget.isDubai ==false){ - // widget.changePageViewIndex!(1), - // if(widget.isDubai ==false){ - - Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)), - } - } - else - { - Navigator.of(context).pop(), - GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 1), () { - AppToast.showErrorToast(message: result); - }), - // projectViewModel.analytics.loginRegistration.login_fail(error: result), - // projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result), - } - }) - .catchError((err) { - print(err); - GifLoaderDialogUtils.hideDialog(context); - Future.delayed(Duration(seconds: 1), () { - AppToast.showErrorToast(message: err); - // startSMSService(tempType); - }); - }); - } else { - authService - .checkActivationCode(request, value) - .then((result) async => { - res = result, - if (result is Map) - { - result = CheckActivationCode.fromJson(result as Map), - if (result.errorCode == '699') - { - //699 block run here - GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 2), () { - AppToast.showErrorToast(message: result.errorEndUserMessage); - Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: WelcomeLogin)); - }) - } - else if (this.registerd_data != null && this.registerd_data.isRegister == true) - { - // widget.changePageViewIndex!(1), - Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)), - } - else - { - sharedPref.remove(FAMILY_FILE), - result.list.isFamily = false, - userData = result.list, - sharedPref.setString(BLOOD_TYPE, result.patientBloodType ?? ""), - //Remove o+ from here Added by Aamir - authenticatedUserObject.user = result.list, - projectViewModel.setPrivilege(privilegeList: res), - await sharedPref.setObject(MAIN_USER, result.list), - await sharedPref.setObject(USER_PROFILE, result.list), - loginTokenID = result.logInTokenID, - await sharedPref.setObject(LOGIN_TOKEN_ID, result.logInTokenID), - await sharedPref.setString(TOKEN, result.authenticationTokenID), - checkIfUserAgreedBefore(result), - // projectViewModel.analytics.loginRegistration.login_successful(), - } + + try { + if (healthId != null || isDubai) { + if (isDubai) request['DOB'] = dob; + request['HealthId'] = healthId; + request['IsHijri'] = isHijri; + + final result = await authService.checkActivationCodeRegister(request, value); + res = result; + + if (result is Map) { + final activation = CheckActivationCode.fromJson(result as Map); + if (registerd_data?.isRegister == true) { + Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); + return; } - else - { - // Navigator.of(context).pop(), - GifLoaderDialogUtils.hideDialog(context), - Future.delayed(Duration(seconds: 1), () { - Navigator.of(context).pop(); - AppToast.showErrorToast(message: result, localContext: context); - startSMSService(tempType); - }), - - // projectViewModel.analytics.loginRegistration.login_fail(error: result), - // projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result) + } else { + GifLoaderDialogUtils.hideDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + projectViewModel.analytics.loginRegistration.login_fail(error: result); + projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result); + } + } else { + final result = await authService.checkActivationCode(request, value); + res = result; + + if (result is Map) { + final activation = CheckActivationCode.fromJson(result as Map); + if (activation.errorCode == '699') { + GifLoaderDialogUtils.hideDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: activation.errorEndUserMessage, + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + return; + } else if (registerd_data?.isRegister == true) { + Navigator.popUntil(context, (route) => Utils.route(route, equalsTo: RegisterNew)); + return; + } else { + sharedPref.remove(FAMILY_FILE); + activation.list!.isFamily = false; + userData = activation.list; + sharedPref.setString(BLOOD_TYPE, activation.patientBloodType ?? ""); + authenticatedUserObject.user = activation.list!; + projectViewModel.setPrivilege(privilegeList: res); + await sharedPref.setObject(MAIN_USER, activation.list); + await sharedPref.setObject(USER_PROFILE, activation.list); + loginTokenID = activation.logInTokenID; + await sharedPref.setObject(LOGIN_TOKEN_ID, activation.logInTokenID); + await sharedPref.setString(TOKEN, activation.authenticationTokenID!); + checkIfUserAgreedBefore(activation); + projectViewModel.analytics.loginRegistration.login_successful(); } - }) - .catchError((err) { - GifLoaderDialogUtils.hideDialog(context); - Future.delayed(Duration(seconds: 1), () { - print(err); - AppToast.showErrorToast(message: err); - // startSMSService(tempType); - }); - }); + } else { + GifLoaderDialogUtils.hideDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: result.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); + projectViewModel.analytics.loginRegistration.login_fail(error: result); + projectViewModel.analytics.errorTracking.log('otp_verification_at_confirm_login', error: result); + } + } + } catch (err) { + GifLoaderDialogUtils.hideDialog(context); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + ), + ); } } - var tempType; - - startSMSService(type) { - tempType = type; - late SMSOTP smsOtp; // Declare the variable first - + void startSMSService(int type) { + late SMSOTP smsOtp; smsOtp = SMSOTP( context, type, phoneNumber, - (code) { - smsOtp.dispose(); // Now we can reference it - this.checkActivationCode(value: code); + (code) { + smsOtp.dispose(); + checkActivationCode(value: code); }, - () { - smsOtp.dispose(); // Now we can reference it + () { + smsOtp.dispose(); Navigator.pop(context); }, ); smsOtp.displayDialog(context); } + Future setDefault() async { + // Load user data from shared preferences + final imeiUserData = await sharedPref.getObject(IMEI_USER_DATA); + if (imeiUserData != null) { + user = SelectDeviceIMEIRES.fromJson(imeiUserData); + } - - setDefault() async { - // showLoader(true); - if (await sharedPref.getObject(IMEI_USER_DATA) != null) user = SelectDeviceIMEIRES.fromJson(await sharedPref.getObject(IMEI_USER_DATA)); - - if (await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN) != null) { + final registerData = await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN); + if (registerData != null) { isMoreOption = true; - this.registerd_data = await CheckPatientAuthenticationReq.fromJson(await sharedPref.getObject(REGISTER_DATA_FOR_LOGIIN)); + registerd_data = CheckPatientAuthenticationReq.fromJson(registerData); } - this.mobileNumber = this.registerd_data != null ? this.registerd_data.patientMobileNumber : int.parse(this.user!.mobile!); - this.zipCode = this.registerd_data != null - ? this.registerd_data.zipCode - : this.user!.outSA == true - ? "971" - : "966"; - this.patientOutSA = this.registerd_data != null - ? this.registerd_data.zipCode == "966" - ? 0 - : 1 - : this.user!.outSA; - if (this.registerd_data != null) { - this.loginTokenID = await sharedPref.getString(LOGIN_TOKEN_ID); - this.loginType = this.registerd_data.searchType; + mobileNumber = registerd_data?.patientMobileNumber ?? int.parse(user?.mobile ?? '0'); + zipCode = registerd_data?.zipCode ?? (user?.outSA == true ? "971" : "966"); + patientOutSA = registerd_data != null ? (registerd_data.zipCode == "966" ? 0 : 1) : user?.outSA; + + if (registerd_data != null) { + loginTokenID = await sharedPref.getString(LOGIN_TOKEN_ID); + loginType = registerd_data.searchType; } - var nhic = await sharedPref.getObject(NHIC_DATA); + + final nhic = await sharedPref.getObject(NHIC_DATA); if (nhic != null) { - final DateFormat dateFormat = DateFormat('MM/dd/yyyy'); - final DateFormat dateFormat2 = DateFormat('dd/MM/yyyy'); + final dateFormat = DateFormat('MM/dd/yyyy'); + final dateFormat2 = DateFormat('dd/MM/yyyy'); dob = nhic['IsHijri'] ? nhic['DateOfBirth'] : dateFormat2.format(dateFormat.parse(nhic['DateOfBirth'])); - isHijri = nhic['IsHijri'] ? 1 : 0; healthId = nhic['HealthId']; } - this.deviceToken = await sharedPref.getString(PUSH_TOKEN); - this.lastLogin = await sharedPref.getInt(LAST_LOGIN) != null - ? await sharedPref.getInt(LAST_LOGIN) - : user != null - ? user!.logInType - : null; - - // showLoader(false); + + deviceToken = await sharedPref.getString(PUSH_TOKEN); + final lastLoginPref = await sharedPref.getInt(LAST_LOGIN); + lastLogin = lastLoginPref ?? user?.logInType; + GifLoaderDialogUtils.hideDialog(context); - //this.cs.sharedService.getStorage(AuthenticationService.LAST_LOGIN); } getCommonRequest({type}) { @@ -623,15 +617,29 @@ class _WelcomeLogin extends State { isArabic: projectViewModel.isArabic, ), ), - (r) => false); + (r) => false); }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); - print(err); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); + // print(err); }); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); - print(err); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); + // print(err); }); } else { goToHome(); @@ -655,18 +663,24 @@ class _WelcomeLogin extends State { Navigator.pushAndRemoveUntil( context, FadePage(page: RateAppointmentDoctor()), - (route) => false, + (route) => false, ); } else { Navigator.pushAndRemoveUntil( context, FadePage(page: LandingPage()), - (route) => false, + (route) => false, ); } insertIMEI(); }).catchError((error) { - print(error); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: error.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); }); } @@ -686,7 +700,14 @@ class _WelcomeLogin extends State { insertIMEI() { authService.insertDeviceImei(selectedOption).then((value) => {}).catchError((err) { - print(err); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: err.toString(), + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); + // print(err); }); } diff --git a/lib/theme/colors.dart b/lib/theme/colors.dart index 8fd52a1b..009b6874 100644 --- a/lib/theme/colors.dart +++ b/lib/theme/colors.dart @@ -31,6 +31,7 @@ class CustomColors { // New UI Colors static const Color bgRedColor = Color(0xFFED1C2B); static const Color bgRedBorderColor = Color(0xFFED1C2B); + static const Color bgRedLightColor = Color(0xFFFEE9EA); diff --git a/lib/uitl/utils.dart b/lib/uitl/utils.dart index 76dfe15b..3d7f8f0b 100644 --- a/lib/uitl/utils.dart +++ b/lib/uitl/utils.dart @@ -16,6 +16,7 @@ import 'package:hmg_patient_app/core/service/client/base_app_client.dart'; import 'package:hmg_patient_app/core/viewModels/project_view_model.dart'; import 'package:hmg_patient_app/extensions/string_extensions.dart'; import 'package:hmg_patient_app/models/Authentication/authenticated_user.dart'; +import 'package:hmg_patient_app/new_ui/new_ext.dart'; import 'package:hmg_patient_app/pages/AlHabibMedicalService/ancillary-orders/ancillaryOrders.dart'; import 'package:hmg_patient_app/pages/MyAppointments/MyAppointments.dart'; import 'package:hmg_patient_app/pages/insurance/insurance_approval_screen.dart'; @@ -59,6 +60,8 @@ import 'package:url_launcher/url_launcher.dart'; import '../Constants.dart'; import '../locator.dart'; +import '../new_ui/exception_widget/ExceptionBottomSheet.dart'; +import '../new_ui/otp/otp_validation_bootmsheet_widget.dart'; import 'app_shared_preferences.dart'; import 'app_toast.dart'; import 'gif_loader_dialog_utils.dart'; @@ -77,13 +80,17 @@ enum GenderType { male, female } enum MaritalStatusType { single, married, divorced, widowed } class Utils { - static int? onOtpBtnPressed(OTPType type, String? phoneNumber) { + static int? onOtpBtnPressed(OTPType type, String? phoneNumber, BuildContext context) { if (phoneNumber == null || phoneNumber.isEmpty) { - Utils.showErrorToast("Please enter your phone number."); + context.showBottomSheet( + child: ExceptionBottomSheet( + message: "Please enter your phone number.", + onOkPressed: () { + Navigator.of(context).pop(); + }, + )); return null; } - - print("Requesting OTP for ${phoneNumber} via ${type == OTPType.whatsapp ? "WhatsApp" : "SMS"} and "); return type == OTPType.sms ? 1 : 4; } @@ -136,7 +143,6 @@ class Utils { } } - static String formatHijriDateToDisplay(String hijriDateString) { try { // Assuming hijriDateString is in the format yyyy-MM-dd @@ -147,10 +153,7 @@ class Utils { final year = parts[0]; // Map month number to short month name (Hijri months) - const hijriMonthNames = [ - 'Muharram', 'Safar', 'Rabi I', 'Rabi II', 'Jumada I', 'Jumada II', - 'Rajab', 'Sha\'ban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\'dah', 'Dhu al-Hijjah' - ]; + const hijriMonthNames = ['Muharram', 'Safar', 'Rabi I', 'Rabi II', 'Jumada I', 'Jumada II', 'Rajab', 'Sha\'ban', 'Ramadan', 'Shawwal', 'Dhu al-Qi\'dah', 'Dhu al-Hijjah']; final monthIndex = int.tryParse(parts[1]) ?? 1; final month = hijriMonthNames[monthIndex - 1]; @@ -161,8 +164,6 @@ class Utils { } } - - static String formatDateToUsage(String isoDateString) { try { final dateTime = DateTime.parse(isoDateString);