mirror of
https://github.com/wger-project/flutter.git
synced 2026-12-05 23:44:02 +01:00
Tell meal item suggestions apart by portion
This commit is contained in:
@@ -245,14 +245,17 @@ class NutritionalPlan with _$NutritionalPlan {
|
||||
return out;
|
||||
}
|
||||
|
||||
/// returns meal items across all meals
|
||||
/// deduped by the combination of amount and ingredient ID
|
||||
/// The meal items across all meals, one per combination of ingredient,
|
||||
/// amount and weight unit.
|
||||
List<MealItem> get dedupMealItems {
|
||||
final List<MealItem> out = [];
|
||||
for (final meal in meals) {
|
||||
for (final mealItem in meal.mealItems) {
|
||||
final found = out.firstWhereOrNull(
|
||||
(e) => e.amount == mealItem.amount && e.ingredientId == mealItem.ingredientId,
|
||||
(e) =>
|
||||
e.amount == mealItem.amount &&
|
||||
e.ingredientId == mealItem.ingredientId &&
|
||||
e.weightUnitId == mealItem.weightUnitId,
|
||||
);
|
||||
|
||||
if (found == null) {
|
||||
|
||||
@@ -137,6 +137,27 @@ void main() {
|
||||
expect(result[3], same(otherIngredient));
|
||||
});
|
||||
|
||||
test('dedupMealItems keeps the same amount in another unit', () {
|
||||
const cup = IngredientWeightUnit(
|
||||
id: 1,
|
||||
uuid: '00000000-0000-0000-0000-000000000001',
|
||||
ingredientId: 1,
|
||||
name: 'Cup',
|
||||
grams: 80,
|
||||
);
|
||||
final grams = MealItem(ingredientId: 1, amount: 2);
|
||||
final cups = MealItem(ingredientId: 1, amount: 2, weightUnitId: cup.id, weightUnitObj: cup);
|
||||
final plan = NutritionalPlan(
|
||||
description: 'portions',
|
||||
startDate: DateTime(2026, 3, 1),
|
||||
meals: [
|
||||
Meal(planId: '', mealItems: [grams, cups]),
|
||||
],
|
||||
);
|
||||
|
||||
expect(plan.dedupMealItems, [grams, cups]);
|
||||
});
|
||||
|
||||
group('dedupDiaryEntries', () {
|
||||
const cup = IngredientWeightUnit(
|
||||
id: 1,
|
||||
|
||||
Reference in New Issue
Block a user