getProductFreshness static method
Future<Map<String, ProductFreshness> >
getProductFreshness({
- required List<
String> barcodes, - required ProductQueryVersion version,
- User? user,
- OpenFoodFactsLanguage? language,
- OpenFoodFactsCountry? country,
- UriProductHelper uriHelper = uriHelperFoodProd,
Returns the ProductFreshness for all the barcodes
.
Implementation
static Future<Map<String, ProductFreshness>> getProductFreshness({
required final List<String> barcodes,
required final ProductQueryVersion version,
final User? user,
final OpenFoodFactsLanguage? language,
final OpenFoodFactsCountry? country,
final UriProductHelper uriHelper = uriHelperFoodProd,
}) async {
final SearchResult searchResult = await searchProducts(
user,
ProductSearchQueryConfiguration(
parametersList: [BarcodeParameter.list(barcodes)],
language: language,
country: country,
fields: [
ProductField.BARCODE,
ProductField.ECOSCORE_SCORE,
ProductField.NUTRISCORE,
ProductField.INGREDIENTS_TAGS,
ProductField.LAST_MODIFIED,
ProductField.STATES_TAGS,
],
version: version,
),
uriHelper: uriHelper,
);
final Map<String, ProductFreshness> result = <String, ProductFreshness>{};
if (searchResult.products == null) {
return result;
}
for (final Product product in searchResult.products!) {
result[product.barcode!] = ProductFreshness.fromProduct(product);
}
return result;
}