Skip to content

Commit 47a5f4a

Browse files
committed
ingredient popup: scroll and shrink image when appropriate
1 parent 4a87c0b commit 47a5f4a

File tree

1 file changed

+41
-31
lines changed

1 file changed

+41
-31
lines changed

lib/widgets/nutrition/helpers.dart

Lines changed: 41 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -116,41 +116,51 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
116116
goals = ingredient!.nutritionalValues.toGoals();
117117
source = ingredient.sourceName ?? 'unknown';
118118
}
119+
var radius = 100.0;
120+
final height = MediaQuery.sizeOf(context).height;
121+
final width = MediaQuery.sizeOf(context).width;
122+
final smallest = height < width ? height : width;
123+
if (smallest < 400) {
124+
radius = smallest / 4;
125+
}
119126
return AlertDialog(
120127
title: (snapshot.hasData) ? Text(ingredient!.name) : null,
121-
content: Padding(
122-
padding: const EdgeInsets.all(8.0),
123-
child: Column(
124-
mainAxisSize: MainAxisSize.min,
125-
children: [
126-
if (image != null) CircleAvatar(backgroundImage: NetworkImage(image), radius: 128),
127-
if (image != null) const SizedBox(height: 12),
128-
if (snapshot.hasError)
129-
Text(
130-
'Ingredient lookup error: ${snapshot.error ?? 'unknown error'}',
131-
style: const TextStyle(color: Colors.red),
132-
),
133-
if (!snapshot.hasData && !snapshot.hasError) const CircularProgressIndicator(),
134-
if (snapshot.hasData)
135-
ConstrainedBox(
136-
constraints: const BoxConstraints(minWidth: 400),
137-
child: MacronutrientsTable(
138-
nutritionalGoals: goals!,
139-
plannedValuesPercentage: goals.energyPercentage(),
140-
showGperKg: false,
128+
content: SingleChildScrollView(
129+
child: Padding(
130+
padding: const EdgeInsets.all(8.0),
131+
child: Column(
132+
mainAxisSize: MainAxisSize.min,
133+
children: [
134+
if (image != null)
135+
CircleAvatar(backgroundImage: NetworkImage(image), radius: radius),
136+
if (image != null) const SizedBox(height: 12),
137+
if (snapshot.hasError)
138+
Text(
139+
'Ingredient lookup error: ${snapshot.error ?? 'unknown error'}',
140+
style: const TextStyle(color: Colors.red),
141+
),
142+
if (!snapshot.hasData && !snapshot.hasError) const CircularProgressIndicator(),
143+
if (snapshot.hasData)
144+
ConstrainedBox(
145+
constraints: const BoxConstraints(minWidth: 400),
146+
child: MacronutrientsTable(
147+
nutritionalGoals: goals!,
148+
plannedValuesPercentage: goals.energyPercentage(),
149+
showGperKg: false,
150+
),
141151
),
142-
),
143-
if (snapshot.hasData && ingredient!.licenseObjectURl == null)
144-
Text('Source: ${source!}'),
145-
if (snapshot.hasData && ingredient!.licenseObjectURl != null)
146-
Padding(
147-
padding: const EdgeInsets.only(top: 12),
148-
child: InkWell(
149-
child: Text('Source: ${source!}'),
150-
onTap: () => launchURL(ingredient!.licenseObjectURl!, context),
152+
if (snapshot.hasData && ingredient!.licenseObjectURl == null)
153+
Text('Source: ${source!}'),
154+
if (snapshot.hasData && ingredient!.licenseObjectURl != null)
155+
Padding(
156+
padding: const EdgeInsets.only(top: 12),
157+
child: InkWell(
158+
child: Text('Source: ${source!}'),
159+
onTap: () => launchURL(ingredient!.licenseObjectURl!, context),
160+
),
151161
),
152-
),
153-
],
162+
],
163+
),
154164
),
155165
),
156166
);

0 commit comments

Comments
 (0)