searchPlaceInGoogle function

Future<List<IPhysicalLocation>> searchPlaceInGoogle(
  1. String queryString
)

Implementation

Future<List<IPhysicalLocation>> searchPlaceInGoogle(String queryString) async {
  if (queryString.isEmpty) {
    return [];
  }
  final placesApi =
      gmaps.GoogleMapsPlaces(apiKey: ThirdPartyCreds.googlePlaces.credentials);
  final dev = await infoX.deviceInfo;

  final location = fromGeoPoint(dev.geo);

  final url = location == null
      ? placesApi.buildAutocompleteUrl(input: queryString)
      : placesApi.buildAutocompleteUrl(
          input: queryString,
          location: location,
          origin: location,
        );
  final purl = rproxy.gmaps(url);
  var resp = await http.post(Uri.parse(purl), body: <String, dynamic>{});
  final response = PlacesAutocompleteResponse.fromJson(
      json.decode(resp.body) as Map<String, dynamic>);
  assert(!response.isInvalid, "Response was invalid");
  assert(!response.isDenied, "Response was invalid");
  assert(!response.isOverQueryLimit, "Response was invalid");
  return response.predictions
      .map((e) => IPhysicalLocation.of()..fromGooglePrediction(e))
      .toList();
}