getProductV3 static method

Future<ProductResultV3> getProductV3(
  1. ProductQueryConfiguration configuration, {
  2. User? user,
  3. QueryType? queryType,
})

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

Please read the language mechanics explanation if you intend to show or update data in specific language: https://github.com/openfoodfacts/openfoodfacts-dart/blob/master/DOCUMENTATION.md#about-languages-mechanics

Implementation

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