computeIntakeNutrient method
- {required MealRecordNutrientType type,
- required List<
FoodItemModel> ? foodItems}
摂取した栄養素の合計を計算する
Implementation
@visibleForTesting
IntakeNutrient computeIntakeNutrient({
required MealRecordNutrientType type,
required List<FoodItemModel>? foodItems,
}) {
final total = foodItems
?.map((e) => e.nutrients)
.expand<NutrientModel>((element) => element)
.where(
(element) => element.name == type.code,
)
.map((e) => e.unitConvertedQuantity)
.fold(0.0, (previousValue, element) => previousValue + element);
return IntakeNutrient(
type: type,
amount: total ?? 0,
);
}