Merge pull request 'drilled the lat and lng parameter form viewmodel to the mapper' (#44) from feature/search_by_region into master

Reviewed-on: #44
pull/48/head
Haroon6138 1 month ago
commit 05500e4cd1

@ -7,10 +7,9 @@ import 'package:hmg_patient_app_new/features/my_appointments/models/resp_models/
class DoctorMapper{ class DoctorMapper{
static Future<RegionList> getMappedDoctor(List<DoctorList> doctorList, static Future<RegionList> getMappedDoctor(List<DoctorList> doctorList,
{bool isArabic = false}) async { {bool isArabic = false,double lat = 0.0,double long = 0.0}) async {
RegionList regionList = RegionList(); RegionList regionList = RegionList();
final lat = await Utils.getNumFromPrefs(CacheConst.userLat);
final long = await Utils.getNumFromPrefs(CacheConst.userLat);
for (var element in doctorList) { for (var element in doctorList) {
String? region = element.getRegionName(isArabic); String? region = element.getRegionName(isArabic);
@ -126,11 +125,9 @@ class DoctorMapper{
static Future<RegionList> getMappedHospitals( static Future<RegionList> getMappedHospitals(
List<HospitalsModel> hospitalList, { List<HospitalsModel> hospitalList, {
bool isArabic = false, bool isArabic = false, double lat = 0.0,double lng = 0.0
}) async { }) async {
final regionList = RegionList(); final regionList = RegionList();
final lat = await Utils.getNumFromPrefs(CacheConst.userLat);
final long = await Utils.getNumFromPrefs(CacheConst.userLat);
for (final hospital in hospitalList) { for (final hospital in hospitalList) {
final region = hospital.getRegionName(isArabic); final region = hospital.getRegionName(isArabic);
if (region == null) continue; if (region == null) continue;
@ -173,13 +170,13 @@ class DoctorMapper{
} else if (distance < regionData.hmgDistance) { } else if (distance < regionData.hmgDistance) {
regionData.hmgDistance = distance; regionData.hmgDistance = distance;
} }
} else if ( lat != 0&& } else if ( lat != 0.0&&
long != 0 && lng != 0.0 &&
hospital.latitude != null && hospital.latitude != null &&
hospital.longitude != null) { hospital.longitude != null) {
double calculatedDistance = calculateDistance( double calculatedDistance = calculateDistance(
lat.toDouble(), lat,
long.toDouble(), lng,
double.parse(hospital.latitude!), double.parse(hospital.latitude!),
double.parse(hospital.longitude!), double.parse(hospital.longitude!),
).abs(); ).abs();

@ -425,7 +425,10 @@ class BookAppointmentsViewModel extends ChangeNotifier {
} else if (apiResponse.messageStatus == 1) { } else if (apiResponse.messageStatus == 1) {
var projectList = apiResponse.data!; var projectList = apiResponse.data!;
hospitalList = await DoctorMapper.getMappedHospitals(projectList, hospitalList = await DoctorMapper.getMappedHospitals(projectList,
isArabic: false); isArabic: false,
lat: _appState.userLat,
lng: _appState.userLong,
);
var lat = await Utils.getNumFromPrefs(CacheConst.userLat); var lat = await Utils.getNumFromPrefs(CacheConst.userLat);
var lng = await Utils.getNumFromPrefs(CacheConst.userLong); var lng = await Utils.getNumFromPrefs(CacheConst.userLong);

Loading…
Cancel
Save