From c03da1c541e7c77c9b6be4ba20bd5b9be03a438f Mon Sep 17 00:00:00 2001 From: haroon amjad Date: Tue, 15 Sep 2026 12:28:11 +0300 Subject: [PATCH] Locale fix --- .../book_appointments_view_model.dart | 111 ++++++++++-------- lib/main.dart | 2 + .../book_appointment_page.dart | 2 + 3 files changed, 63 insertions(+), 52 deletions(-) diff --git a/lib/features/book_appointments/book_appointments_view_model.dart b/lib/features/book_appointments/book_appointments_view_model.dart index dbed528e..a4530eee 100644 --- a/lib/features/book_appointments/book_appointments_view_model.dart +++ b/lib/features/book_appointments/book_appointments_view_model.dart @@ -1,6 +1,7 @@ import 'dart:async'; import 'package:easy_localization/easy_localization.dart'; +import 'package:firebase_crashlytics/firebase_crashlytics.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:hmg_patient_app_new/core/app_state.dart'; @@ -842,67 +843,73 @@ class BookAppointmentsViewModel extends ChangeNotifier { } Future getDoctorFreeSlots({bool isBookingForLiveCare = false, Function(dynamic)? onSuccess, Function(String)? onError}) async { - docFreeSlots.clear(); - DateTime date; - final DateFormat formatter = DateFormat('HH:mm', "en-US"); - final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); - Map _eventsParsed; - - final result = await bookAppointmentsRepo.getDoctorFreeSlots( - selectedDoctor.clinicID ?? 0, - selectedDoctor.projectID ?? 0, - selectedDoctor.doctorID ?? 0, - isBookingForLiveCare, - continueDentalPlan: isContinueDentalPlan, - onError: onError, - ); - - result.fold( - (failure) async { - print(failure); - if (onError != null) { - onError(failure.message); - } - }, - (apiResponse) { - if (apiResponse.messageStatus == 2) { - onError!(apiResponse.errorMessage ?? "Unknown error occurred"); - // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); - } else if (apiResponse.messageStatus == 1) { - if (apiResponse.data['FreeTimeSlots'] == null || apiResponse.data['FreeTimeSlots'].isEmpty) { - onError!("No free slots available".tr()); - return; + // try { + docFreeSlots.clear(); + DateTime date; + final DateFormat formatter = DateFormat('HH:mm', "en-US"); + // final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); + // Map _eventsParsed; + + final result = await bookAppointmentsRepo.getDoctorFreeSlots( + selectedDoctor.clinicID ?? 0, + selectedDoctor.projectID ?? 0, + selectedDoctor.doctorID ?? 0, + isBookingForLiveCare, + continueDentalPlan: isContinueDentalPlan, + onError: onError, + ); + + result.fold( + (failure) async { + print(failure); + if (onError != null) { + onError(failure.message); } - initialSlotDuration = apiResponse.data["InitialSlotDuration"]; - freeSlotsResponse = apiResponse.data['FreeTimeSlots']; - isWaitingAppointmentAvailable = apiResponse.data["IsAllowToBookWaitingAppointment"]; - - // isWaitingAppointmentAvailable = true; - - freeSlotsResponse.forEach((element) { - // date = (isLiveCareSchedule != null && isLiveCareSchedule) - // ? DateUtil.convertStringToDate(element) - // : - date = DateUtil.convertStringToDateSaudiTimezone(element, int.parse(selectedDoctor.projectID.toString())); - slotsList.add(FreeSlot(date, ['slot'])); - docFreeSlots.add(TimeSlot(isoTime: formatter.format(date), start: new DateTime(date.year, date.month, date.day, 0, 0, 0, 0), end: date, vidaDate: element)); - }); + }, + (apiResponse) { + if (apiResponse.messageStatus == 2) { + onError!(apiResponse.errorMessage ?? "Unknown error occurred"); + // dialogService.showErrorDialog(message: apiResponse.errorMessage!, onOkPressed: () {}); + } else if (apiResponse.messageStatus == 1) { + if (apiResponse.data['FreeTimeSlots'] == null || apiResponse.data['FreeTimeSlots'].isEmpty) { + onError!("No free slots available".tr()); + return; + } + initialSlotDuration = apiResponse.data["InitialSlotDuration"]; + freeSlotsResponse = apiResponse.data['FreeTimeSlots']; + isWaitingAppointmentAvailable = apiResponse.data["IsAllowToBookWaitingAppointment"]; + + // isWaitingAppointmentAvailable = true; + + freeSlotsResponse.forEach((element) { + // date = (isLiveCareSchedule != null && isLiveCareSchedule) + // ? DateUtil.convertStringToDate(element) + // : + date = DateUtil.convertStringToDateSaudiTimezone(element, int.parse(selectedDoctor.projectID.toString())); + slotsList.add(FreeSlot(date, ['slot'])); + docFreeSlots.add(TimeSlot(isoTime: formatter.format(date), start: new DateTime(date.year, date.month, date.day, 0, 0, 0, 0), end: date, vidaDate: element)); + }); - notifyListeners(); - if (onSuccess != null) { - onSuccess(apiResponse); + notifyListeners(); + if (onSuccess != null) { + onSuccess(apiResponse); + } } - } - }, - ); + }, + ); + // } catch(ex) { + // if (onError != null) { + // onError(ex.toString()); + // } + // } } Future getLiveCareDoctorFreeSlots({bool isBookingForLiveCare = false, Function(dynamic)? onSuccess, Function(String)? onError}) async { docFreeSlots.clear(); DateTime date; final DateFormat formatter = DateFormat('HH:mm', "en-US"); - final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); - Map _eventsParsed; + // final DateFormat dateFormatter = DateFormat('yyyy-MM-dd'); + // Map _eventsParsed; final result = await bookAppointmentsRepo.getLiveCareDoctorFreeSlots( selectedDoctor.clinicID ?? 0, selectedLiveCareClinic.serviceID ?? 0, selectedDoctor.projectID ?? 0, selectedDoctor.doctorID ?? 0, isBookingForLiveCare, diff --git a/lib/main.dart b/lib/main.dart index 223103ae..4e60c2a0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -117,6 +117,8 @@ Future callInitializations() async { WidgetsFlutterBinding.ensureInitialized(); await EasyLocalization.ensureInitialized(); + Intl.defaultLocale = "en_US"; + SafeDevice.init( SafeDeviceConfig(mockLocationCheckEnabled: false), // disables mock location check on Android ); diff --git a/lib/presentation/book_appointment/book_appointment_page.dart b/lib/presentation/book_appointment/book_appointment_page.dart index 53d4b1b1..c2560ecd 100644 --- a/lib/presentation/book_appointment/book_appointment_page.dart +++ b/lib/presentation/book_appointment/book_appointment_page.dart @@ -523,6 +523,7 @@ class _BookAppointmentPageState extends State { ], ).onPress(() { bookAppointmentsViewModel.setIsDoctorSearchByNameStarted(false); + bookAppointmentsViewModel.setIsLiveCareSchedule(false); bookAppointmentsViewModel.setProjectID(null); Navigator.of(context).push( CustomPageRoute( @@ -554,6 +555,7 @@ class _BookAppointmentPageState extends State { ).onPress(() { Clarity.sendCustomEvent('Select_Region_Page'); bookAppointmentsViewModel.setProjectID(null); + bookAppointmentsViewModel.setIsLiveCareSchedule(false); openRegionListBottomSheet(context, RegionBottomSheetType.FOR_REGION); }), ],