pickData method
Implementation
Future<PickedData> pickData(
{required double latitude, required double longitude}) async {
LatLong latLong = LatLong(latitude: latitude, longitude: longitude);
Map<String, dynamic> decodedResponse =
await HttpRequestCustom.requestWithLatLng(
latitude: latLong.latitude, longitude: latLong.longitude);
notifyListener();
PickedData pickedData = PickedData.fromJson(decodedResponse, latLong);
String postCode = "";
String country = "";
List<String> values = [];
try {
values = pickedData.displayName.split(",");
if (pickedData.address!.postCode.isNotNullOrEmpty()) {
postCode = pickedData.address!.postCode;
} else {
for (var element in values) {
if (element.trim().isZip5Code()) {
postCode = element.trim();
}
}
pickedData.address!.postCode = postCode;
}
} catch (e) {
country = "";
}
try {
if (pickedData.address!.country.isNotNullOrEmpty()) {
country = pickedData.address!.country;
} else {
if (values.isNotEmpty) {
country = values.last.trim();
}
pickedData.address!.country = country;
}
} catch (e) {
country = "";
}
return pickedData;
}