openfoodfacts 0.0.8

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 69

Open Food Facts - Dart

Dart package for the Open Food Facts API.

Content

The following API services are implemented:

getProduct(barcode, language)

Get the product information for an existing barcode. Prepare ingredients, images and product name depending on the specified language.

getProductRaw(barcode)

Get the product information for an existing barcode without additional preparation.

saveProduct(user, product)

Add a new product or edit an existing one, using the specified Open Food Facts user credentials.

addProductImage(user, image)

Add an product image of the front, the ingredients or the nutrition, using the specified Open Food Facts user credentials.

Development

Getting Started

For help getting started with Flutter, view our online flutter docs. For help on editing package code, view the package docs.

auto generate the json classes

By running (in command prompt) flutter packages pub run build_runner build in our project root, you can generate json serialization code for our models whenever needed.

running the unit tests

Adjust the file test_constants.dart to provide your own login credentials (OpenFoodFacts).

publish the package to pub.dartlang.org

run flutter packages pub publish in the project directory

Authors

[0.0.8] - 16.11.2018.

  • getProduct() provides ingredients and images for a given language.
  • getProductRaw() provides all data fields without preparation.

[0.0.6] - 27.10.2018.

  • set dependency versions as range

[0.0.5] - 25.10.2018.

  • upgrade of http 0.12.0
  • upgrade of build_runner 1.0.0

[0.0.4] - 16.10.2018.

  • class Image changed to ProductImage for a easier namespace resolving.

[0.0.3] - 12.10.2018.

  • model of selected product images changed.

[0.0.2] - 3.10.2018.

  • Service saveProduct() can handle to add and to edit a product.
  • Added traces to a product

[0.0.1] - 18.09.2018.

initial version with these API services:

  • add a new product
  • add a new product image
  • get an existing product

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.getProductRaw("barcode");

  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());
    }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  openfoodfacts: ^0.0.8

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:openfoodfacts/openfoodfacts.dart';
  
Version Uploaded Documentation Archive
0.0.8 Nov 16, 2018 Go to the documentation of openfoodfacts 0.0.8 Download openfoodfacts 0.0.8 archive
0.0.7 Oct 28, 2018 Go to the documentation of openfoodfacts 0.0.7 Download openfoodfacts 0.0.7 archive
0.0.6 Oct 28, 2018 Go to the documentation of openfoodfacts 0.0.6 Download openfoodfacts 0.0.6 archive
0.0.5 Oct 25, 2018 Go to the documentation of openfoodfacts 0.0.5 Download openfoodfacts 0.0.5 archive
0.0.4 Oct 16, 2018 Go to the documentation of openfoodfacts 0.0.4 Download openfoodfacts 0.0.4 archive
0.0.3 Oct 12, 2018 Go to the documentation of openfoodfacts 0.0.3 Download openfoodfacts 0.0.3 archive
0.0.2 Oct 3, 2018 Go to the documentation of openfoodfacts 0.0.2 Download openfoodfacts 0.0.2 archive
0.0.1 Sep 18, 2018 Go to the documentation of openfoodfacts 0.0.1 Download openfoodfacts 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
59
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
50
Overall:
Weighted score of the above. [more]
69
Learn more about scoring.

We analyzed this package on Dec 5, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.1.0
  • pana: 0.12.7
  • Flutter: 1.0.0

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Fix lib/model/ImageList.dart. (-0.50 points)

Analysis of lib/model/ImageList.dart reported 1 hint:

line 1 col 8: Unused import: 'package:json_annotation/json_annotation.dart'.

Fix lib/openfoodfacts.dart. (-0.50 points)

Analysis of lib/openfoodfacts.dart reported 1 hint:

line 104 col 25: The method '_login' isn't used.

Maintenance issues and suggestions

Use constrained dependencies. (-20 points)

The pubspec.yaml contains 4 dependencies without version constraints. Specify version ranges for the following dependencies: async_loader, http, path, test.

The description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.54.0 <3.0.0
async_loader >=0.1.2 0.1.2
flutter 0.0.0
http >=0.11.0 0.12.0
json_annotation ^1.0.0 1.2.0 2.0.0
path >=1.6.2 1.6.2
test >=1.3.0 1.5.1+1
Transitive dependencies
analyzer 0.34.0
args 1.5.1
async 2.0.8
boolean_selector 1.0.4
charcode 1.1.2
collection 1.14.11
convert 2.0.2
crypto 2.0.6
csslib 0.14.6
front_end 0.1.7
glob 1.1.7
html 0.13.3+3
http_multi_server 2.0.5
http_parser 3.1.3
io 0.3.3
js 0.6.1+1
json_rpc_2 2.0.9
kernel 0.3.7
logging 0.11.3+2
matcher 0.12.3+1 0.12.4
meta 1.1.6
mime 0.9.6+2
multi_server_socket 1.0.2
node_preamble 1.4.4
package_config 1.0.5
package_resolver 1.0.6
plugin 0.2.0+3
pool 1.3.6
pub_semver 1.4.2
shelf 0.7.3+3
shelf_packages_handler 1.0.4
shelf_static 0.2.8
shelf_web_socket 0.2.2+4
sky_engine 0.0.99
source_map_stack_trace 1.1.5
source_maps 0.10.8
source_span 1.4.1
stack_trace 1.9.3
stream_channel 1.6.8
string_scanner 1.0.4
term_glyph 1.0.1
test_api 0.2.1
test_core 0.2.0+1
typed_data 1.1.6
utf 0.9.0+5
vector_math 2.0.8
vm_service_client 0.2.6
watcher 0.9.7+10
web_socket_channel 1.0.9
yaml 2.1.15
Dev dependencies
build_runner >=0.10.0
flutter_test
json_serializable ^1.0.0