@@ -38,10 +38,9 @@ class NutritionPlansProvider with ChangeNotifier {
38
38
static const _nutritionalPlansInfoPath = 'nutritionplaninfo' ;
39
39
static const _mealPath = 'meal' ;
40
40
static const _mealItemPath = 'mealitem' ;
41
- static const _ingredientPath = 'ingredient ' ;
41
+ static const _ingredientInfoPath = 'ingredientinfo ' ;
42
42
static const _ingredientSearchPath = 'ingredient/search' ;
43
43
static const _nutritionDiaryPath = 'nutritiondiary' ;
44
- static const _ingredientImagePath = 'ingredient-image' ;
45
44
46
45
final WgerBaseProvider baseProvider;
47
46
List <NutritionalPlan > _plans = [];
@@ -131,6 +130,7 @@ class NutritionPlansProvider with ChangeNotifier {
131
130
try {
132
131
plan = findById (planId);
133
132
} on NoSuchEntryException {
133
+ // TODO: remove this useless call, because we will fetch all details below
134
134
plan = await fetchAndSetPlanSparse (planId);
135
135
}
136
136
@@ -144,6 +144,7 @@ class NutritionPlansProvider with ChangeNotifier {
144
144
final List <MealItem > mealItems = [];
145
145
final meal = Meal .fromJson (mealData);
146
146
147
+ // TODO: we should add these ingredients to the ingredient cache
147
148
for (final mealItemData in mealData['meal_items' ]) {
148
149
final mealItem = MealItem .fromJson (mealItemData);
149
150
@@ -298,7 +299,7 @@ class NutritionPlansProvider with ChangeNotifier {
298
299
// Get ingredient from the server and save to cache
299
300
} on StateError {
300
301
final data = await baseProvider.fetch (
301
- baseProvider.makeUrl (_ingredientPath , id: ingredientId),
302
+ baseProvider.makeUrl (_ingredientInfoPath , id: ingredientId),
302
303
);
303
304
ingredient = Ingredient .fromJson (data);
304
305
_ingredients.add (ingredient);
@@ -370,14 +371,15 @@ class NutritionPlansProvider with ChangeNotifier {
370
371
371
372
// Send the request
372
373
final data = await baseProvider.fetch (
373
- baseProvider.makeUrl (_ingredientPath , query: {'code' : code}),
374
+ baseProvider.makeUrl (_ingredientInfoPath , query: {'code' : code}),
374
375
);
375
376
376
377
if (data['count' ] == 0 ) {
377
378
return null ;
378
- } else {
379
- return Ingredient .fromJson (data['results' ][0 ]);
380
379
}
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 ]);
381
383
}
382
384
383
385
/// Log meal to nutrition diary
0 commit comments