Properly log meal diary entries

This commit is contained in:
Roland Geider
2021-01-31 14:49:26 +01:00
parent 9c25816fa6
commit d3eaa11cf9
2 changed files with 6 additions and 2 deletions

View File

@@ -66,6 +66,7 @@ class Log {
Log.fromMealItem(MealItem mealItem) {
this.ingredientId = mealItem.ingredientId;
this.ingredientObj = mealItem.ingredientObj;
this.weightUnit = null;
this.amount = mealItem.amount;
}

View File

@@ -268,10 +268,13 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
//var meal = findMealById(mealId);
for (var item in meal.mealItems) {
Log log = Log.fromMealItem(item);
log.planId = findById(meal.plan).id;
final plan = findById(meal.plan);
log.planId = plan.id;
log.datetime = DateTime.now();
await post(log.toJson(), makeUrl(_nutritionDiaryPath));
final data = await post(log.toJson(), makeUrl(_nutritionDiaryPath));
log.id = data['id'];
plan.logs.add(log);
}
notifyListeners();
}