getPlaceDetails method

Future<PlaceDetailsResult> getPlaceDetails({
  1. String? sessionToken,
  2. String? placeId,
  3. String fields = "formatted_address,geometry,place_id,address_components",
})

Implementation

Future<PlaceDetailsResult> getPlaceDetails(
    {String? sessionToken,
      String? placeId,
      String fields = "formatted_address,geometry,place_id,address_components"}) async {
  Map<String, String> requestHeaders = {
    HttpHeaders.contentTypeHeader: "application/json",
    HttpHeaders.acceptHeader: "application/json",
  };
  Map<String, String> queryParameters = {
    'sessiontoken': "$sessionToken",
    'place_id': "$placeId",
    'key': "$apiKey",
    'fields': "$fields"
  };
  Uri uri =
  Uri.https(endpoint, "maps/api/place/details/json", queryParameters);
  final response = await client.get(uri, headers: requestHeaders);
  if (response.statusCode == 200 ||
      response.statusCode == 201 ||
      response.statusCode == 203 ||
      response.statusCode == 204) {
    return PlaceDetailsResult.fromJson(json.decode(response.body));
  } else if (response.body != null) {
    throw Exception(response.body);
  } else {
    throw Exception('${response.toString()}');
  }
}