getAutocompletedSuggestions static method

  1. @Deprecated('Use getSuggestions instead')
Future<List> getAutocompletedSuggestions(
  1. TagType taxonomyType, {
  2. String input = '',
  3. OpenFoodFactsLanguage language = OpenFoodFactsLanguage.ENGLISH,
  4. QueryType? queryType,
  5. int limit = 25,
})

Returns suggestions.

The limit has a max value of 400 on the server side.

  List<dynamic> suggestions =
      await OpenFoodAPIClient.getAutocompletedSuggestions(
    TagType.CATEGORIES,
    input: 'Mil',
  );

  print(suggestions); // [Milk drinks fermented with Bifidus, Milk drinks fermented with L casei, Milk jams]

Implementation

// TODO: deprecated from 2023-02-01; remove when old enough
@Deprecated('Use getSuggestions instead')
static Future<List<dynamic>> getAutocompletedSuggestions(
  final TagType taxonomyType, {
  final String input = '',
  final OpenFoodFactsLanguage language = OpenFoodFactsLanguage.ENGLISH,
  final QueryType? queryType,
  final int limit = 25,
}) async {
  final Uri uri = UriHelper.getPostUri(
    path: '/cgi/suggest.pl',
    queryType: queryType,
  );
  final Map<String, String> queryParameters = <String, String>{
    'tagtype': taxonomyType.offTag,
    'term': input,
    'lc': language.offTag,
    'limit': limit.toString(),
  };
  final Response response = await HttpHelper().doPostRequest(
    uri,
    queryParameters,
    null,
    queryType: queryType,
    addCredentialsToBody: false,
  );
  return HttpHelper().jsonDecode(response.body);
}