getProductV3 static method

Future<ProductResultV3> getProductV3(
  1. ProductQueryConfiguration configuration, {
  2. User? user,
  3. UriProductHelper uriHelper = uriHelperFoodProd,
})

The ProductResultV3 does not contain a product, if the product is not available. ingredients, images and product name will be prepared for the given language.

Example:

  ProductQueryConfiguration config = ProductQueryConfiguration(
    '5449000131805',
    version: ProductQueryVersion.v3,
  );
  ProductResultV3 product = await OpenFoodAPIClient.getProductV3(config);
  print(product.product?.productName); // Coca Cola Zero
  print(product.product?.brands); // Coca-Cola
  print(product.product?.quantity); // 330ml
  print(product.product?.nutriments?.getValue(Nutrient.salt, PerSize.oneHundredGrams)); // 0.0212
  print(product.product?.additives?.names); // [E150d, E338, E950, E951]
  print(product.product?.allergens?.names); // []

This product contains:

  • Product images (Product image by field, size and language, current fields are: Front, Ingredients, Nutrition, Packaging)
  • Additives, Allergens, Environment impact, Ingredient analysis, Nutrient levels, Nutrition facts (incl. micro-nutrients)
  • Language dependant fields (like ingredients, product name, packaging text)
  • Eco-Score, Nutri-Score, NOVA groups
  • Translated, high-level and customizable product information (Attributes)
  • Product completion status

A detailed list of all returned data can be found in Product.

Using the ProductQueryConfiguration you can specify more query parameters like for example the language to query.

Implementation

static Future<ProductResultV3> getProductV3(
  ProductQueryConfiguration configuration, {
  User? user,
  final UriProductHelper uriHelper = uriHelperFoodProd,
}) async {
  if (!configuration.matchesV3()) {
    Exception("The configuration must match V3!");
  }
  final String productString = await getProductString(
    configuration,
    user: user,
    uriHelper: uriHelper,
  );
  final String jsonStr = _replaceQuotes(productString);
  final ProductResultV3 result = ProductResultV3.fromJson(
    HttpHelper().jsonDecode(jsonStr),
  );
  if (result.product != null) {
    ProductHelper.removeImages(result.product!, configuration.language);
    ProductHelper.createImageUrls(result.product!, uriHelper: uriHelper);
  }
  return result;
}