buildAutocompleteUrl method

String buildAutocompleteUrl({
  1. required String input,
  2. String? sessionToken,
  3. num? offset,
  4. Location? origin,
  5. Location? location,
  6. num? radius,
  7. String? language,
  8. List<String> types = const [],
  9. List<Component> components = const [],
  10. bool strictbounds = false,
  11. String? region,
})

Implementation

String buildAutocompleteUrl({
  required String input,
  String? sessionToken,
  num? offset,
  Location? origin,
  Location? location,
  num? radius,
  String? language,
  List<String> types = const [],
  List<Component> components = const [],
  bool strictbounds = false,
  String? region,
}) {
  final params = <String, String>{
    'input': input,
  };

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

  if (origin != null) {
    params['origin'] = origin.toString();
  }

  if (location != null) {
    params['location'] = location.toString();
  }

  if (radius != null) {
    params['radius'] = radius.toString();
  }

  if (types.isNotEmpty) {
    params['types'] = types.join('|');
  }

  if (components.isNotEmpty) {
    params['components'] = components.join('|');
  }

  if (strictbounds) {
    params['strictbounds'] = strictbounds.toString();
  }

  if (offset != null) {
    params['offset'] = offset.toString();
  }

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

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

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

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