calculateEnergy static method
Calculates the energy for 100g in kJ. ! should be used cautiously (might not be displayed to the end user) ! source : https://en.wikipedia.org/wiki/Food_energy
Implementation
static double? calculateEnergy(
Nutriments nutriments, {
PerSize perSize = PerSize.oneHundredGrams,
}) {
double? fat = nutriments.getValue(Nutrient.fat, perSize);
double? carbs = nutriments.getValue(Nutrient.carbohydrates, perSize);
double? proteins = nutriments.getValue(Nutrient.proteins, perSize);
double? fiber = nutriments.getValue(Nutrient.fiber, perSize);
if (fat == null || carbs == null || proteins == null || fiber == null) {
return null;
}
return (fat * 37 + carbs * 17 + proteins * 17 + fiber * 8);
}