Skip to content

Commit

Permalink
ingredient popup: fix image rendering
Browse files Browse the repository at this point in the history
  • Loading branch information
Dieterbe committed Jul 12, 2024
1 parent 5fa0889 commit d99ca41
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 10 deletions.
6 changes: 5 additions & 1 deletion lib/widgets/nutrition/forms.dart
Original file line number Diff line number Diff line change
Expand Up @@ -454,7 +454,11 @@ class IngredientFormState extends State<IngredientForm> {
IconButton(
icon: const Icon(Icons.info_outline),
onPressed: () {
showIngredientDetails(context, suggestions[index].ingredient.id);
showIngredientDetails(
context,
suggestions[index].ingredient.id,
image: suggestions[index].ingredient.image?.image,
);
},
),
const SizedBox(width: 5),
Expand Down
9 changes: 1 addition & 8 deletions lib/widgets/nutrition/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,12 +102,6 @@ String getKcalConsumedVsPlanned(Meal meal, BuildContext context) {
}

void showIngredientDetails(BuildContext context, int id, {String? image}) {
// when loading recently used ingredients, we never get an image :'(
// we also don't get an image when querying the API
// however, the typeahead suggestion does get an image, so we allow passing it...

final serverURL = context.read<NutritionPlansProvider>().baseProvider.auth.serverUrl;

showDialog(
context: context,
builder: (context) => FutureBuilder<Ingredient>(
Expand All @@ -133,8 +127,7 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
if (image != null)
CircleAvatar(backgroundImage: NetworkImage(serverURL! + image), radius: 128),
if (image != null) CircleAvatar(backgroundImage: NetworkImage(image), radius: 128),
if (image != null) const SizedBox(height: 12),
if (snapshot.hasError)
Text(
Expand Down
6 changes: 5 additions & 1 deletion lib/widgets/nutrition/widgets.dart
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,11 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
trailing: IconButton(
icon: const Icon(Icons.info_outline),
onPressed: () {
showIngredientDetails(context, suggestion.data.id, image: suggestion.data.image);
showIngredientDetails(
context,
suggestion.data.id,
image: suggestion.data.image != null ? url! + suggestion.data.image! : null,
);
},
),
);
Expand Down

0 comments on commit d99ca41

Please sign in to comment.