getAutoCompletePlaces method
Implementation
Future<PlacesPredictions> getAutoCompletePlaces(
{String? sessionToken,
String? input,
required String types,
required String countries}) async {
Map<String, String> requestHeaders = {
HttpHeaders.contentTypeHeader: "application/json",
HttpHeaders.acceptHeader: "application/json",
};
Map<String, String> queryParameters = {
'sessiontoken': "$sessionToken",
'input': "$input",
'key': "$apiKey",
//'types': "$types",
'components': "${convertCountryListToString(countries)}",
};
Uri uri = Uri.https(
endpoint, "maps/api/place/autocomplete/json", queryParameters);
final response = await client.get(uri, headers: requestHeaders);
if (response.statusCode == 200 ||
response.statusCode == 201 ||
response.statusCode == 203 ||
response.statusCode == 204) {
return PlacesPredictions.fromJson(json.decode(response.body));
} else if (response.body.isNotEmpty) {
throw Exception(response.body);
} else {
throw Exception('${response.toString()}');
}
}