getPredictions method

Future<List<AddressPrediction>> getPredictions(
  1. String query,
  2. String countryCode, {
  3. String? locale,
  4. LocationInput? location,
  5. bool deleteThisPartOfCache = false,
})

query user input to get predictions from. Often called on every input change countryCode e.g. DE for germany

Implementation

Future<List<AddressPrediction>> getPredictions(
  String query,
  String countryCode, {
  String? locale,
  LocationInput? location,
  bool deleteThisPartOfCache = false,
}) async {
  final QueryOptions _options = WatchQueryOptions(
    document: gql(getAddressPredictions),
    variables: {
      'query': query,
      'countryCode': countryCode,
      'locale': locale ?? Intl.getCurrentLocale(),
      'location': location?.toJson(),
    },
  );
  final QueryResult result = await _graphQLClient.query(_options);
  checkForError(result);
  if (deleteThisPartOfCache) {
    _graphQLClient.cache.writeQuery(_options.asRequest, data: {});
  }
  return (result.data!['predictions'] as List)
      .map((e) => AddressPrediction.fromJson(e))
      .toList();
}