From 22ab9b7d2dc158da01ea3ee9276621403a5d8d14 Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Sun, 16 Aug 2026 15:47:39 +0300 Subject: [PATCH] Crashlytics fixes --- .../authentication_view_model.dart | 8 +++-- .../medical_file/medical_file_view_model.dart | 12 ++++++-- lib/features/payfort/payfort_repo.dart | 30 +++++++++++++++++++ lib/features/payfort/payfort_view_model.dart | 20 +++++++++++++ .../widgets/appointment_doctor_card.dart | 13 ++++---- .../book_appointment_page.dart | 3 +- lib/widgets/in_app_browser/InAppBrowser.dart | 3 ++ lib/widgets/input_widget.dart | 3 +- 8 files changed, 76 insertions(+), 16 deletions(-) diff --git a/lib/features/authentication/authentication_view_model.dart b/lib/features/authentication/authentication_view_model.dart index 7688cfa4..72ca42cb 100644 --- a/lib/features/authentication/authentication_view_model.dart +++ b/lib/features/authentication/authentication_view_model.dart @@ -824,7 +824,11 @@ class AuthenticationViewModel extends ChangeNotifier { onSuccess: (dynamic respData) async { try { if (respData != null) { - dynamic data = await SelectDeviceByImeiRespModelElement.fromJson(respData.toJson()); + SelectDeviceByImeiRespModelElement data = SelectDeviceByImeiRespModelElement.fromJson(respData.toJson()); + if (data.mobile == null || data.mobile == "" || data.identificationNo == null || data.identificationNo == "") { + return; + } + _appState.setSelectDeviceByImeiRespModelElement(data); LoaderBottomSheet.hideLoader(); @@ -856,8 +860,6 @@ class AuthenticationViewModel extends ChangeNotifier { } Future checkUserAuthentication({required OTPTypeEnum otpTypeEnum, Function(dynamic)? onSuccess, Function(String)? onError}) async { - // TODO: THIS SHOULD BE REMOVED LATER ON AND PASSED FROM APP STATE DIRECTLY INTO API CLIENT. BECAUSE THIS API ONLY NEEDS FEW PARAMS FROM USER - loginTypeEnum = otpTypeEnum == OTPTypeEnum.sms ? LoginTypeEnum.sms : LoginTypeEnum.whatsapp; // if (phoneNumberController.text.isEmpty) { diff --git a/lib/features/medical_file/medical_file_view_model.dart b/lib/features/medical_file/medical_file_view_model.dart index 6fb8c8a2..a9bfb09c 100644 --- a/lib/features/medical_file/medical_file_view_model.dart +++ b/lib/features/medical_file/medical_file_view_model.dart @@ -45,7 +45,6 @@ class MedicalFileViewModel extends ChangeNotifier { List patientSickLeavesViewList = []; bool isSickLeavesSortByClinic = true; - bool isSickLeavesDataNeedsReloading = true; List patientAllergiesList = []; @@ -61,6 +60,7 @@ class MedicalFileViewModel extends ChangeNotifier { List patientMedicalReportsViewList = []; bool isMedicalReportsSortByClinic = true; + bool isMedicalReportsDataNeedsReloading = true; List patientMedicalReportAppointmentHistoryList = []; PatientAppointmentHistoryResponseModel? patientMedicalReportSelectedAppointment; @@ -192,7 +192,7 @@ class MedicalFileViewModel extends ChangeNotifier { } setIsPatientMedicalReportsLoading(bool val) { - if (val) { + if (val && isMedicalReportsDataNeedsReloading) { onMedicalReportTabChange(0); patientMedicalReportList.clear(); patientMedicalReportsByClinic.clear(); @@ -200,8 +200,8 @@ class MedicalFileViewModel extends ChangeNotifier { patientMedicalReportsViewList.clear(); patientMedicalReportPDFBase64 = ""; isMedicalReportsSortByClinic = true; + isPatientMedicalReportsListLoading = val; } - isPatientMedicalReportsListLoading = val; notifyListeners(); } @@ -373,6 +373,10 @@ class MedicalFileViewModel extends ChangeNotifier { } Future getPatientMedicalReportList({Function(dynamic)? onSuccess, Function(String)? onError}) async { + if (!isMedicalReportsDataNeedsReloading) { + return; + } + patientMedicalReportList.clear(); patientMedicalReportRequestedList.clear(); patientMedicalReportReadyList.clear(); @@ -385,6 +389,7 @@ class MedicalFileViewModel extends ChangeNotifier { (failure) async => await errorHandlerService.handleError( failure: failure, onOkPressed: () { + isMedicalReportsDataNeedsReloading = true; onError!(failure.message); }, ), @@ -400,6 +405,7 @@ class MedicalFileViewModel extends ChangeNotifier { } onMedicalReportTabChange(0); isPatientMedicalReportsListLoading = false; + isMedicalReportsDataNeedsReloading = false; notifyListeners(); if (onSuccess != null) { onSuccess(apiResponse); diff --git a/lib/features/payfort/payfort_repo.dart b/lib/features/payfort/payfort_repo.dart index 3cd27a9d..9262d662 100644 --- a/lib/features/payfort/payfort_repo.dart +++ b/lib/features/payfort/payfort_repo.dart @@ -3,6 +3,7 @@ import 'package:dartz/dartz.dart'; import 'package:hmg_patient_app_new/core/api/api_client.dart'; import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/common_models/generic_api_model.dart'; +import 'package:hmg_patient_app_new/core/common_models/tamara_request_model.dart'; import 'package:hmg_patient_app_new/core/exceptions/api_failure.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/get_tamara_installments_details_response_model.dart'; import 'package:hmg_patient_app_new/features/payfort/models/apple_pay_request_insert_model.dart'; @@ -34,6 +35,8 @@ abstract class PayfortRepo { Future>> payfortRequestInsert({required PayfortRequestInsertModel payfortRequestInsertModel}); Future>> payfortResponseInsert({required PayfortResponseInsertModel payfortResponseInsertModel}); + + Future>> tamaraRequestInsert({required TamaraRequestModel tamaraRequestModel}); } class PayfortRepoImp implements PayfortRepo { @@ -350,4 +353,31 @@ class PayfortRepoImp implements PayfortRepo { return Left(UnknownFailure(e.toString())); } } + + @override + Future> tamaraRequestInsert({required TamaraRequestModel tamaraRequestModel}) async { + try { + GenericApiModel? apiResponse; + Failure? failure; + await apiClient.post(TAMARA_REQUEST_INSERT, body: tamaraRequestModel.toJson(), onFailure: (error, statusCode, {messageStatus, failureType}) { + failure = failureType; + }, onSuccess: (response, statusCode, {messageStatus, errorMessage}) { + try { + apiResponse = GenericApiModel( + messageStatus: messageStatus, + statusCode: statusCode, + errorMessage: null, + data: response, + ); + } catch (e) { + failure = DataParsingFailure(e.toString()); + } + }, isAllowAny: true, isPaymentServices: true); + if (failure != null) return Left(failure!); + if (apiResponse == null) return Left(ServerFailure("Unknown error")); + return Right(apiResponse!); + } catch (e) { + return Left(UnknownFailure(e.toString())); + } + } } diff --git a/lib/features/payfort/payfort_view_model.dart b/lib/features/payfort/payfort_view_model.dart index f567264f..031c3182 100644 --- a/lib/features/payfort/payfort_view_model.dart +++ b/lib/features/payfort/payfort_view_model.dart @@ -9,6 +9,7 @@ import 'package:flutter_amazonpaymentservices/flutter_amazonpaymentservices.dart import 'package:hmg_patient_app_new/core/api_consts.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; import 'package:hmg_patient_app_new/core/cache_consts.dart'; +import 'package:hmg_patient_app_new/core/common_models/tamara_request_model.dart'; import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/get_tamara_installments_details_response_model.dart'; @@ -116,6 +117,25 @@ class PayfortViewModel extends ChangeNotifier { ); } + Future tamaraRequestInsert({required TamaraRequestModel tamaraRequestModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { + final result = await payfortRepo.tamaraRequestInsert(tamaraRequestModel: tamaraRequestModel); + + result.fold( + (failure) async => await errorHandlerService.handleError(failure: failure), + (apiResponse) { + if (apiResponse.messageStatus == 2) { + // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); + } else if (apiResponse.messageStatus == 1) { + // payfortProjectDetailsRespModel = apiResponse.data!; + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } + } + }, + ); + } + Future payfortResponseInsert({required PayfortResponseInsertModel payfortResponseInsertModel, Function(dynamic)? onSuccess, Function(String)? onError}) async { final result = await payfortRepo.payfortResponseInsert(payfortResponseInsertModel: payfortResponseInsertModel); diff --git a/lib/presentation/appointments/widgets/appointment_doctor_card.dart b/lib/presentation/appointments/widgets/appointment_doctor_card.dart index 6e3f77d1..8738a449 100644 --- a/lib/presentation/appointments/widgets/appointment_doctor_card.dart +++ b/lib/presentation/appointments/widgets/appointment_doctor_card.dart @@ -152,16 +152,13 @@ class AppointmentDoctorCard extends StatelessWidget { ), AppCustomChipWidget( labelPadding: EdgeInsetsDirectional.only(start: -6.w, end: 6.w), - icon: !patientAppointmentHistoryResponseModel.isLiveCareAppointment! - ? AppAssets.walkin_appointment_icon + icon: !(patientAppointmentHistoryResponseModel.isLiveCareAppointment ?? false) ? AppAssets.walkin_appointment_icon : AppAssets.small_livecare_icon, - iconColor: !patientAppointmentHistoryResponseModel.isLiveCareAppointment! ? AppColors.textColor : Colors.white, - labelText: patientAppointmentHistoryResponseModel.isLiveCareAppointment! - ? LocaleKeys.livecare.tr(context: context) + iconColor: !(patientAppointmentHistoryResponseModel.isLiveCareAppointment ?? false) ? AppColors.textColor : Colors.white, + labelText: (patientAppointmentHistoryResponseModel.isLiveCareAppointment ?? false) ? LocaleKeys.livecare.tr(context: context) : LocaleKeys.walkin.tr(context: context), - backgroundColor: - !patientAppointmentHistoryResponseModel.isLiveCareAppointment! ? AppColors.greyColor : AppColors.successColor, - textColor: !patientAppointmentHistoryResponseModel.isLiveCareAppointment! ? AppColors.textColor : Colors.white, + backgroundColor: !(patientAppointmentHistoryResponseModel.isLiveCareAppointment ?? false) ? AppColors.greyColor : AppColors.successColor, + textColor: !(patientAppointmentHistoryResponseModel.isLiveCareAppointment ?? false) ? AppColors.textColor : Colors.white, ), ], ), diff --git a/lib/presentation/book_appointment/book_appointment_page.dart b/lib/presentation/book_appointment/book_appointment_page.dart index cb93d9e0..be91951a 100644 --- a/lib/presentation/book_appointment/book_appointment_page.dart +++ b/lib/presentation/book_appointment/book_appointment_page.dart @@ -389,7 +389,8 @@ class _BookAppointmentPageState extends State { crossAxisAlignment: CrossAxisAlignment.center, children: [ Utils.buildImgWithNetwork( - url: myAppointmentsVM.patientFavouriteDoctorsList[index].doctorImageUrl!, + url: myAppointmentsVM.patientFavouriteDoctorsList[index].doctorImageUrl ?? "https://eservices-test-bucket.s3.me-central-1.amazonaws.com/unkown_male.png", + // url: myAppointmentsVM.patientFavouriteDoctorsList[index].doctorImageUrl!, iconColor: AppColors.transparent, width: 64.h, height: 64.h, diff --git a/lib/widgets/in_app_browser/InAppBrowser.dart b/lib/widgets/in_app_browser/InAppBrowser.dart index e8370e5b..7f4836f6 100644 --- a/lib/widgets/in_app_browser/InAppBrowser.dart +++ b/lib/widgets/in_app_browser/InAppBrowser.dart @@ -11,6 +11,7 @@ import 'package:hmg_patient_app_new/core/dependencies.dart'; import 'package:hmg_patient_app_new/core/utils/date_util.dart'; import 'package:hmg_patient_app_new/core/utils/utils.dart'; import 'package:hmg_patient_app_new/features/authentication/models/resp_models/authenticated_user_resp_model.dart'; +import 'package:hmg_patient_app_new/features/payfort/payfort_view_model.dart'; enum _PAYMENT_TYPE { PACKAGES, PHARMACY, PATIENT } @@ -217,6 +218,8 @@ class MyInAppBrowser extends InAppBrowser { tamaraRequestModel.appointmentDate = (appoDate != null && appoDate != "") ? appoDate : null; tamaraRequestModel.isSchedule = ((appoNo != null && appoNo != "") && (appoDate != null && appoDate != "")) ? true : false; + getIt.get().tamaraRequestInsert(tamaraRequestModel: tamaraRequestModel); + // service.tamaraInsertRequest(tamaraRequestModel, context).then((res) { // // if (context != null) GifLoaderDialogUtils.hideDialog(context); generateTamaraURL(amount, orderDesc, transactionID, projId, emailId, paymentMethod, patientType, patientName, patientID, authenticatedUser, isLiveCareAppo, servID, LiveServID, appoDate, appoNo, diff --git a/lib/widgets/input_widget.dart b/lib/widgets/input_widget.dart index b7fe686f..b1214b87 100644 --- a/lib/widgets/input_widget.dart +++ b/lib/widgets/input_widget.dart @@ -198,7 +198,8 @@ class TextInputWidget extends StatelessWidget { ], ), ), - (suffix != null) ? suffix! : SizedBox.shrink() + // (suffix != null) ? suffix : SizedBox.shrink() + suffix ?? SizedBox.shrink() ], ), ),