autocomplete method

Future<Response<PlacesAutocompleteResponse>> autocomplete(
  1. String input, {
  2. String? sessiontoken,
  3. String? components,
  4. bool? strictbounds,
  5. num? offset,
  6. String? origin,
  7. String? location,
  8. num? radius,
  9. String? types,
  10. String? language,
  11. CancelToken? cancelToken,
  12. Map<String, dynamic>? headers,
  13. Map<String, dynamic>? extra,
  14. ValidateStatus? validateStatus,
  15. ProgressCallback? onSendProgress,
  16. ProgressCallback? onReceiveProgress,
})

The Place Autocomplete service is a web service that returns place predictions in response to an HTTP request. The request specifies a textual search string and optional geographic bounds. The service can be used to provide autocomplete functionality for text-based geographic searches, by returning places such as businesses, addresses and points of interest as a user types. <div class="note">Note: You can use Place Autocomplete even without a map. If you do show a map, it must be a Google map. When you display predictions from the Place Autocomplete service without a map, you must include the 'Powered by Google' logo. The Place Autocomplete service can match on full words and substrings, resolving place names, addresses, and plus codes. Applications can therefore send queries as the user types, to provide on-the-fly place predictions. The returned predictions are designed to be presented to the user to aid them in selecting the desired place. You can send a Place Details request for more information about any of the places which are returned.

Implementation

Future<Response<PlacesAutocompleteResponse>> autocomplete(
  String input, {
  String? sessiontoken,
  String? components,
  bool? strictbounds,
  num? offset,
  String? origin,
  String? location,
  num? radius,
  String? types,
  String? language,
  CancelToken? cancelToken,
  Map<String, dynamic>? headers,
  Map<String, dynamic>? extra,
  ValidateStatus? validateStatus,
  ProgressCallback? onSendProgress,
  ProgressCallback? onReceiveProgress,
}) async {
  final _request = RequestOptions(
    path: r'/maps/api/place/autocomplete/json',
    method: 'GET',
    headers: <String, dynamic>{
      ...?headers,
    },
    queryParameters: <String, dynamic>{
      r'input': input,
      if (sessiontoken != null) r'sessiontoken': sessiontoken,
      if (components != null) r'components': components,
      if (strictbounds != null) r'strictbounds': strictbounds,
      if (offset != null) r'offset': offset,
      if (origin != null) r'origin': origin,
      if (location != null) r'location': location,
      if (radius != null) r'radius': radius,
      if (types != null) r'types': types,
      if (language != null) r'language': language,
    },
    extra: <String, dynamic>{
      'secure': <Map<String, String>>[
        {
          'type': 'apiKey',
          'name': 'ApiKeyAuth',
          'keyName': 'key',
          'where': 'query',
        },
      ],
      ...?extra,
    },
    validateStatus: validateStatus,
    contentType: 'application/json',
    cancelToken: cancelToken,
    onSendProgress: onSendProgress,
    onReceiveProgress: onReceiveProgress,
  );

  dynamic _bodyData;

  final _response = await _dio.request<dynamic>(
    _request.path,
    data: _bodyData,
    options: Options(
      method: _request.method,
      sendTimeout: _request.sendTimeout,
      receiveTimeout: _request.receiveTimeout,
      extra: _request.extra,
      headers: _request.headers,
      responseType: _request.responseType,
      contentType: _request.contentType,
      validateStatus: _request.validateStatus,
      receiveDataWhenStatusError: _request.receiveDataWhenStatusError,
      followRedirects: _request.followRedirects,
      maxRedirects: _request.maxRedirects,
      requestEncoder: _request.requestEncoder,
      listFormat: _request.listFormat,
    ),
  );

  const _responseType = FullType(PlacesAutocompleteResponse);
  final _responseData = _serializers.deserialize(
    _response.data,
    specifiedType: _responseType,
  ) as PlacesAutocompleteResponse?;

  return Response<PlacesAutocompleteResponse>(
    data: _responseData,
    headers: _response.headers,
    isRedirect: _response.isRedirect,
    requestOptions: _response.requestOptions,
    redirects: _response.redirects,
    statusCode: _response.statusCode,
    statusMessage: _response.statusMessage,
    extra: _response.extra,
  );
}