getProduct static method

  1. @Deprecated('Use getProductV3 instead')
Future<ProductResult> getProduct(
  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

// TODO: deprecated from 2022-12-01; remove when old enough
@Deprecated('Use getProductV3 instead')
static Future<ProductResult> getProduct(
  ProductQueryConfiguration configuration, {
  User? user,
  QueryType? queryType,
}) async {
  if (configuration.matchesV3()) {
    Exception("The configuration must not match V3!");
  }
  final String productString = await getProductString(
    configuration,
    user: user,
    queryType: queryType,
  );
  final String jsonStr = _replaceQuotes(productString);
  final ProductResult result = ProductResult.fromJson(jsonDecode(jsonStr));
  if (result.product != null) {
    ProductHelper.removeImages(result.product!, configuration.language);
    ProductHelper.createImageUrls(result.product!, queryType: queryType);
  }
  return result;
}