mirror of
https://github.com/wger-project/flutter.git
synced 2026-02-18 00:17:48 +01:00
Fix bug preventing addind and editing meal items
This commit is contained in:
@@ -67,8 +67,10 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
|
||||
Meal? findMealById(int id) {
|
||||
for (var plan in _plans) {
|
||||
var meal = plan.meals.firstWhere((plan) => plan.id == id);
|
||||
return meal;
|
||||
try {
|
||||
var meal = plan.meals.firstWhere((plan) => plan.id == id);
|
||||
return meal;
|
||||
} on StateError catch (e) {}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -201,8 +203,7 @@ class Nutrition extends WgerBaseProvider with ChangeNotifier {
|
||||
}
|
||||
|
||||
/// Adds a meal item to a meal
|
||||
Future<MealItem> addMealItem(MealItem mealItem, int mealId) async {
|
||||
var meal = findMealById(mealId)!;
|
||||
Future<MealItem> addMealItem(MealItem mealItem, Meal meal) async {
|
||||
final data = await post(mealItem.toJson(), makeUrl(_mealItemPath));
|
||||
|
||||
mealItem = MealItem.fromJson(data);
|
||||
|
||||
@@ -177,7 +177,7 @@ class MealItemForm extends StatelessWidget {
|
||||
_form.currentState!.save();
|
||||
|
||||
try {
|
||||
Provider.of<Nutrition>(context, listen: false).addMealItem(_mealItem, _meal.id!);
|
||||
Provider.of<Nutrition>(context, listen: false).addMealItem(_mealItem, _meal);
|
||||
} on WgerHttpException catch (error) {
|
||||
showHttpExceptionErrorDialog(error, context);
|
||||
} catch (error) {
|
||||
|
||||
Reference in New Issue
Block a user