Skip to content

Commit d99ca41

Browse files
committed
ingredient popup: fix image rendering
1 parent 5fa0889 commit d99ca41

File tree

3 files changed

+11
-10
lines changed

3 files changed

+11
-10
lines changed

lib/widgets/nutrition/forms.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -454,7 +454,11 @@ class IngredientFormState extends State<IngredientForm> {
454454
IconButton(
455455
icon: const Icon(Icons.info_outline),
456456
onPressed: () {
457-
showIngredientDetails(context, suggestions[index].ingredient.id);
457+
showIngredientDetails(
458+
context,
459+
suggestions[index].ingredient.id,
460+
image: suggestions[index].ingredient.image?.image,
461+
);
458462
},
459463
),
460464
const SizedBox(width: 5),

lib/widgets/nutrition/helpers.dart

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -102,12 +102,6 @@ String getKcalConsumedVsPlanned(Meal meal, BuildContext context) {
102102
}
103103

104104
void showIngredientDetails(BuildContext context, int id, {String? image}) {
105-
// when loading recently used ingredients, we never get an image :'(
106-
// we also don't get an image when querying the API
107-
// however, the typeahead suggestion does get an image, so we allow passing it...
108-
109-
final serverURL = context.read<NutritionPlansProvider>().baseProvider.auth.serverUrl;
110-
111105
showDialog(
112106
context: context,
113107
builder: (context) => FutureBuilder<Ingredient>(
@@ -133,8 +127,7 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
133127
child: Column(
134128
mainAxisSize: MainAxisSize.min,
135129
children: [
136-
if (image != null)
137-
CircleAvatar(backgroundImage: NetworkImage(serverURL! + image), radius: 128),
130+
if (image != null) CircleAvatar(backgroundImage: NetworkImage(image), radius: 128),
138131
if (image != null) const SizedBox(height: 12),
139132
if (snapshot.hasError)
140133
Text(

lib/widgets/nutrition/widgets.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,11 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
163163
trailing: IconButton(
164164
icon: const Icon(Icons.info_outline),
165165
onPressed: () {
166-
showIngredientDetails(context, suggestion.data.id, image: suggestion.data.image);
166+
showIngredientDetails(
167+
context,
168+
suggestion.data.id,
169+
image: suggestion.data.image != null ? url! + suggestion.data.image! : null,
170+
);
167171
},
168172
),
169173
);

0 commit comments

Comments
 (0)