getOrderedNutrientsJsonString static method

Future<String> getOrderedNutrientsJsonString({
  1. required OpenFoodFactsCountry country,
  2. required OpenFoodFactsLanguage language,
  3. UriProductHelper uriHelper = uriHelperFoodProd,
})

Returns the nutrient hierarchy specific to a country, localized, as JSON Use OpenFoodAPIClient.getOrderedNutrients to get them as a OrderedNutrient object.

Implementation

static Future<String> getOrderedNutrientsJsonString({
  required final OpenFoodFactsCountry country,
  required final OpenFoodFactsLanguage language,
  final UriProductHelper uriHelper = uriHelperFoodProd,
}) async {
  final Uri uri = uriHelper.getPostUri(
    path: 'cgi/nutrients.pl',
  );
  Map<String, String> queryParameters = <String, String>{
    'cc': country.offTag,
    'lc': language.offTag,
  };
  final Response response = await HttpHelper().doPostRequest(
    uri,
    queryParameters,
    null,
    uriHelper: uriHelper,
    addCredentialsToBody: false,
  );
  if (response.statusCode != 200) {
    throw Exception('Could not retrieve ordered nutrients!');
  }
  return response.body;
}