saveCurrentLocation method

dynamic saveCurrentLocation()

Implementation

saveCurrentLocation() async {
  final selectedPlace = selectedAddress.value;
  if (selectedPlace == null) return;
  try {
    String? city;
    String? state;
    String? country;
    String? postcode;

    for (var component in selectedPlace.addressComponents) {
      if (component.types.contains('locality')) {
        city = component.longName;
      } else if (component.types.contains('administrative_area_level_1')) {
        state = component.longName;
      } else if (component.types.contains('country')) {
        country = component.longName;
      } else if (component.types.contains('postal_code')) {
        postcode = component.longName;
      }
    }

    debugPrint("selectedLocLatLng----> ${selectedPlace.geometry.location.lat}----${selectedPlace.geometry.location.lng}");

    address = address ?? UFUAddressModel();

    address!
      ..placeId = selectedPlace.placeId
      ..address = selectedPlace.formattedAddress
      ..completeAddress = selectedPlace.formattedAddress
      ..address1 = selectedPlace.formattedAddress
      ..address2 = null
      ..latitude = selectedPlace.geometry.location.lat
      ..longitude = selectedPlace.geometry.location.lng
      ..city = city
      ..state = state
      ..country = country
      ..postcode = postcode;

    Get.back(result: address);
  } catch (e) {
    UFUtils.handleError(e);
  }
}