import 'dart:convert'; import 'dart:developer'; import 'dart:io'; class FoodFactLookupClient { FoodFactLookupClient(); static const String host = "world.openfoodfacts.org"; static const String url = "https://world.openfoodfacts.org/api/v3/product/"; String getProductUrl(String ean) { return "$url$ean.json"; } Future retrieveFoodInfo(String ean) async { HttpClient client = HttpClient(); var request = await client.getUrl(Uri.parse(getProductUrl(ean))); var response = await request.close(); var asString = await response.transform(utf8.decoder).join(); return FoodFactModel.fromJson(jsonDecode(asString)); } } class FoodFactModel { final String name; FoodFactModel({required this.name}); factory FoodFactModel.fromJson(Map json) { log("key product.product_name: ${json['product']['product_name']}"); return FoodFactModel(name: json['product']['product_name']); } }