From 265d979b48950d3e8dbb67e415cfcc3522ab9e1e Mon Sep 17 00:00:00 2001 From: "taha.alam" Date: Thu, 18 Sep 2025 09:25:19 +0300 Subject: [PATCH] drilled the lat and lng parameter form viewmodel to the mapper --- lib/core/utils/doctor_response_mapper.dart | 17 +++++++---------- .../book_appointments_view_model.dart | 5 ++++- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/lib/core/utils/doctor_response_mapper.dart b/lib/core/utils/doctor_response_mapper.dart index fd0cb79..bff4598 100644 --- a/lib/core/utils/doctor_response_mapper.dart +++ b/lib/core/utils/doctor_response_mapper.dart @@ -7,10 +7,9 @@ import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/ class DoctorMapper{ static Future getMappedDoctor(List doctorList, - {bool isArabic = false}) async { + {bool isArabic = false,double lat = 0.0,double long = 0.0}) async { RegionList regionList = RegionList(); - final lat = await Utils.getNumFromPrefs(CacheConst.userLat); - final long = await Utils.getNumFromPrefs(CacheConst.userLat); + for (var element in doctorList) { String? region = element.getRegionName(isArabic); @@ -126,11 +125,9 @@ class DoctorMapper{ static Future getMappedHospitals( List hospitalList, { - bool isArabic = false, + bool isArabic = false, double lat = 0.0,double lng = 0.0 }) async { final regionList = RegionList(); - final lat = await Utils.getNumFromPrefs(CacheConst.userLat); - final long = await Utils.getNumFromPrefs(CacheConst.userLat); for (final hospital in hospitalList) { final region = hospital.getRegionName(isArabic); if (region == null) continue; @@ -173,13 +170,13 @@ class DoctorMapper{ } else if (distance < regionData.hmgDistance) { regionData.hmgDistance = distance; } - } else if ( lat != 0&& - long != 0 && + } else if ( lat != 0.0&& + lng != 0.0 && hospital.latitude != null && hospital.longitude != null) { double calculatedDistance = calculateDistance( - lat.toDouble(), - long.toDouble(), + lat, + lng, double.parse(hospital.latitude!), double.parse(hospital.longitude!), ).abs(); diff --git a/lib/features/book_appointments/book_appointments_view_model.dart b/lib/features/book_appointments/book_appointments_view_model.dart index c2b9639..c74b176 100644 --- a/lib/features/book_appointments/book_appointments_view_model.dart +++ b/lib/features/book_appointments/book_appointments_view_model.dart @@ -425,7 +425,10 @@ class BookAppointmentsViewModel extends ChangeNotifier { } else if (apiResponse.messageStatus == 1) { var projectList = apiResponse.data!; hospitalList = await DoctorMapper.getMappedHospitals(projectList, - isArabic: false); + isArabic: false, + lat: _appState.userLat, + lng: _appState.userLong, + ); var lat = await Utils.getNumFromPrefs(CacheConst.userLat); var lng = await Utils.getNumFromPrefs(CacheConst.userLong);