fetchPlaceDetails method
Fetch place details by ID.
Implementation
Future<TGooglePlaceDetailsResponse> fetchPlaceDetails(
String placeId, {
List<String> fields = defaultPlaceDetailsFields,
String? sessionToken,
}) async {
final apiKey = _resolveApiKey();
if (apiKey == null || apiKey.isEmpty) {
throw Exception('Google Map API Key not resolved.');
}
final id = placeId.startsWith('places/') ? placeId.split('/').last : placeId;
final response = await _dio.get(
'https://places.googleapis.com/v1/places/$id',
queryParameters: {
if (sessionToken != null && sessionToken.isNotEmpty) 'sessionToken': sessionToken,
},
options: Options(
headers: {
'X-Goog-Api-Key': apiKey,
'X-Goog-FieldMask': fields.join(','),
},
),
);
if (response.data is Map<String, dynamic>) {
return TGooglePlaceDetailsResponse.fromJson(response.data as Map<String, dynamic>);
}
throw Exception('Invalid response format from Place Details API.');
}