computeIntakeNutrient method
- {required MealRecordNutrientType type,
- required List<
MealRecordModel> records}
摂取した栄養素の合計を計算する
Implementation
@visibleForTesting
IntakeNutrient computeIntakeNutrient({
required MealRecordNutrientType type,
required List<MealRecordModel> records,
}) {
final total = records
.map((e) => e.foodItems)
.expand<FoodItemModel>((element) {
if (element == null) {
return [];
}
return element;
})
.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,
);
}