buildDetailsUrl method

String buildDetailsUrl({
  1. String? placeId,
  2. String? reference,
  3. String? sessionToken,
  4. String? language,
  5. List<String> fields = const [],
  6. String? region,
})

Implementation

String buildDetailsUrl({
  String? placeId,
  String? reference,
  String? sessionToken,
  String? language,
  List<String> fields = const [],
  String? region,
}) {
  if (placeId != null && reference != null) {
    throw ArgumentError("You must supply either 'placeid' or 'reference'");
  }

  final params = <String, String>{};

  if (placeId != null) {
    params['placeid'] = placeId;
  }

  if (reference != null) {
    params['reference'] = reference;
  }

  if (language != null) {
    params['language'] = language;
  }

  if (region != null) {
    params['region'] = region;
  }

  if (fields.isNotEmpty) {
    params['fields'] = fields.join(',');
  }

  if (apiKey != null) {
    params['key'] = apiKey!;
  }

  if (sessionToken != null) {
    params['sessiontoken'] = sessionToken;
  }

  return url
      .replace(
        path: '${url.path}$_detailsSearchUrl',
        queryParameters: params,
      )
      .toString();
}