openfoodfacts Dart 包提供了对 Open Food Facts API 的便捷访问,这是一个由全球用户共同贡献的食品产品协作数据库。它使开发者能够获取详细的食品信息,例如成分、营养数据、过敏原和条形码信息。该包专为跨平台应用设计,支持 Android、iOS、Web、macOS、Windows 和 Linux。该包简化了与 Open Food Facts 数据库的集成,非常适合专注于食品透明度、饮食追踪或营养分析的应用程序。
适合场景
通过条形码查找食品产品
营养信息检索
过敏原和成分扫描
饮食追踪应用程序
可持续食品选择研究
主要特点
跨平台兼容性
实时产品数据访问
支持条形码和关键词搜索
开源且由社区驱动
简单 API 集成
适合对象
健康与保健应用
食品标签工具
饮食管理平台
教育类食品科学应用
注重可持续性的应用程序
使用建议
依赖外部API的可用性
数据质量因用户贡献而异
需要互联网连接以进行实时查询
有限的离线功能
在高使用量期间可能会应用速率限制
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Open Food Facts - Dart
Dart package for the Open Food Facts API. Free and Easy access to more than 2.9 million food products information from all around the world.
Open Food Facts is powered by contributors from around the world and is constantly growing thanks to them.
General principles, how does it work ?
We use the ability of the Open Food Facts API to return products results in JSON, we then generate easily understandable objects structures to make it simple for you to use.
This plugin also allows you to edit a product or upload a new one to Open Food Facts. Using the same simple product structure you can create a product object or edit an existing one and send it to the API using a single function.
Weekly meetings (currently inactive)
We e-meet on Fridays at 09:00 Paris Time (08:00 London Time, 11:30 IST, 12:00 AM PT)
Weekly Agenda: please add the Agenda items as early as you can. Make sure to check the Agenda items in advance of the meeting, so that we have the most informed discussions possible, leading to argumented decisions.
The meeting will handle Agenda items first, and if time permits, collaborative bug triage.
We strive to timebox the core of the meeting (decision making) to 30 minutes, with an optional free discussion/live debugging afterwards.
We take comprehensive notes in the Weekly Agenda of agenda item discussions and of decisions taken.
For most queries no authentication is required! :)
Though we recommend to set a User-Agent to not to be blocked by mistake.
Setup (Optional)
At the beginning of the app you can define some global settings so that they don't need to be specified in each query. You can override these static values at any time in the app lifecycle.
Some queries which modify or enter data need a user account to validate this request.
There are multiple ways to handle user accounts:
Let your users login / create Open Food Facts user accounts (Recommended)
Create a global user for your app through which all requests run
Currently there is no OAuth workflow, therefor a user is just a User object in this package.
So you need to get the username as well as the password from the users and store it somewhere save. For Flutter apps we recommend using the flutter_secure_storage package
For the user to be taken into account you have mount a global user at one point in your app lifecycle:
Regardless if you are using a global app or accounts per user. After mounting this, the user will be added to queries where the user can be attributed.
Some methods in OpenFoodAPIClient require to pass a User, there you can access the before mounted user with:
If your users do not expect a specific result immediately (eg. Inventory apps)
Send photos (front/nutrition/ingredients/packaging): most painless thing for your users
The Open Food Facts AI Robotoff will generate some derived data from the photos
Overtime, other apps, and the Open Food Facts community will fill the data gaps
If your users do expect a result immediately (eg Nutrition apps, Scoring apps…)
Send nutrition facts + category > get the Nutri-Score
Send ingredients > get the NOVA group (about food ultra-processing), additives, allergens, normalized ingredients, vegan, vegetarian…
Send category (strict minimum) + labels + origins of ingredients + packaging (photo and text) > get the Eco-Score (about environmental impact)
Open Data License
The database in under the OdBL. This means attributing the source and also contributing back any additions (photos, data), which this package makes easy to do.
You can check the terms of use here : Terms of use.
If you are having issues, that go beyond the scope of this package, please write to us on Slack or send us an email at reuse@openfoodfacts.org (or contact@openfoodfacts if not related to reuse)
Testing
Execute the following command from the root of the repository to run the tests:
dart test
Applications using this SDK
Official application
Open Food Facts (Codename Smoothie) is the official app developed by Open Food Facts, which is available on Android and iOS. The source code is also available on GitHub.