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{
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();
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<RegionList> getMappedHospitals(
List<HospitalsModel> 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();

@ -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);

Loading…
Cancel
Save