@@ -38,10 +38,9 @@ class NutritionPlansProvider with ChangeNotifier {
3838 static const _nutritionalPlansInfoPath = 'nutritionplaninfo' ;
3939 static const _mealPath = 'meal' ;
4040 static const _mealItemPath = 'mealitem' ;
41- static const _ingredientPath = 'ingredient ' ;
41+ static const _ingredientInfoPath = 'ingredientinfo ' ;
4242 static const _ingredientSearchPath = 'ingredient/search' ;
4343 static const _nutritionDiaryPath = 'nutritiondiary' ;
44- static const _ingredientImagePath = 'ingredient-image' ;
4544
4645 final WgerBaseProvider baseProvider;
4746 List <NutritionalPlan > _plans = [];
@@ -131,6 +130,7 @@ class NutritionPlansProvider with ChangeNotifier {
131130 try {
132131 plan = findById (planId);
133132 } on NoSuchEntryException {
133+ // TODO: remove this useless call, because we will fetch all details below
134134 plan = await fetchAndSetPlanSparse (planId);
135135 }
136136
@@ -144,6 +144,7 @@ class NutritionPlansProvider with ChangeNotifier {
144144 final List <MealItem > mealItems = [];
145145 final meal = Meal .fromJson (mealData);
146146
147+ // TODO: we should add these ingredients to the ingredient cache
147148 for (final mealItemData in mealData['meal_items' ]) {
148149 final mealItem = MealItem .fromJson (mealItemData);
149150
@@ -298,7 +299,7 @@ class NutritionPlansProvider with ChangeNotifier {
298299 // Get ingredient from the server and save to cache
299300 } on StateError {
300301 final data = await baseProvider.fetch (
301- baseProvider.makeUrl (_ingredientPath , id: ingredientId),
302+ baseProvider.makeUrl (_ingredientInfoPath , id: ingredientId),
302303 );
303304 ingredient = Ingredient .fromJson (data);
304305 _ingredients.add (ingredient);
@@ -370,14 +371,15 @@ class NutritionPlansProvider with ChangeNotifier {
370371
371372 // Send the request
372373 final data = await baseProvider.fetch (
373- baseProvider.makeUrl (_ingredientPath , query: {'code' : code}),
374+ baseProvider.makeUrl (_ingredientInfoPath , query: {'code' : code}),
374375 );
375376
376377 if (data['count' ] == 0 ) {
377378 return null ;
378- } else {
379- return Ingredient .fromJson (data['results' ][0 ]);
380379 }
380+ // TODO we should probably add it to ingredient cache.
381+ // TODO: we could also use the ingredient cache for code searches
382+ return Ingredient .fromJson (data['results' ][0 ]);
381383 }
382384
383385 /// Log meal to nutrition diary
0 commit comments