openfoodfacts 0.1.13
openfoodfacts: ^0.1.13

Flutter Android iOS

dart package for the Open Food Facts API, a food products database made by everyone, for everyone.

example/lib/main.dart

import 'package:openfoodfacts/openfoodfacts.dart';

/// request a product from the OpenFoodFacts database
Future<Product> getProduct() async {
  var barcode = "0048151623426";
  ProductResult result =
      await OpenFoodAPIClient.getProduct("barcode", User.LANGUAGE_DE);

  if (result.status == 1) {
    return result.product;
  } else {
    throw new Exception("product not found, please insert data for " + barcode);
  }
}

/// add a new product to the OpenFoodFacts database
void addNewProduct() async {
  // define the product to be added.
  // more attributes available ...
  Product myProduct = new Product(
    barcode: "0048151623426",
    productName: "Maryland Choc Chip",
  );

  // a registered user login for https://world.openfoodfacts.org/ is required
  User myUser = new User(userId: "max@off.com", password: "password");

  // query the OpenFoodFacts API
  Status result = await OpenFoodAPIClient.saveProduct(myUser, myProduct);

  if (result.status != 1) {
    throw new Exception("product could not be added: " + result.error);
  }
}

/// add a new image for an existing product of the OpenFoodFacts database
void addProductImage() async {
  // define the product image
  // set the uri to the local image file
  // choose the "imageField" as location / description of the image content.
  SendImage image = new SendImage(
    lang: "en",
    barcode: "0048151623426",
    imageField: ProductImage.FIELD_INGREDIENTS,
    imageUrl: Uri.parse("assets/ingredients_en.jpg"),
  );

  // a registered user login for https://world.openfoodfacts.org/ is required
  User myUser = new User(userId: "max@off.com", password: "password");

  // query the OpenFoodFacts API
  Status result = await OpenFoodAPIClient.addProductImage(myUser, image);

  if (result.status != "status ok") {
    throw new Exception("image could not be uploaded: " +
        result.error +
        " " +
        result.imageId.toString());
  }
}
14
likes
80
pub points
69%
popularity

dart package for the Open Food Facts API, a food products database made by everyone, for everyone.

Repository (GitHub)
View/report issues

Uploaders

a.schaefer@playsys.de
primael@reefind.com
peter.w.v.jorgensen@gmail.com

License

Apache 2.0 (LICENSE)

Dependencies

async_loader, flutter, http, image, json_annotation, path

More

Packages that depend on openfoodfacts