getSuggestions static method
Future<List<String> >
getSuggestions(
- TagType taxonomyType, {
- String input = '',
- required OpenFoodFactsLanguage language,
- OpenFoodFactsCountry? country,
- String? categories,
- String? shape,
- int limit = 25,
- UriProductHelper uriHelper = uriHelperFoodProd,
- User? user,
Consider using SuggestionManager.
Implementation
static Future<List<String>> getSuggestions(
final TagType taxonomyType, {
final String input = '',
required final OpenFoodFactsLanguage language,
final OpenFoodFactsCountry? country,
final String? categories,
final String? shape,
final int limit = 25,
final UriProductHelper uriHelper = uriHelperFoodProd,
final User? user,
}) async {
final Map<String, String> queryParameters = <String, String>{
'tagtype': taxonomyType.offTag,
'lc': language.offTag,
'string': input,
if (country != null) 'cc': country.offTag,
if (categories != null) 'categories': categories,
if (shape != null) 'shape': shape,
'limit': limit.toString(),
};
final Uri uri = uriHelper.getUri(
path: '/api/v3/taxonomy_suggestions',
queryParameters: queryParameters,
);
final Response response = await HttpHelper().doGetRequest(
uri,
user: user,
uriHelper: uriHelper,
);
final Map<String, dynamic> map = HttpHelper().jsonDecode(response.body);
final List<String> result = <String>[];
if (map['suggestions'] != null) {
for (dynamic value in map['suggestions']) {
result.add(value.toString());
}
}
return result;
}