19
19
import 'package:flutter/material.dart' ;
20
20
import 'package:flutter_gen/gen_l10n/app_localizations.dart' ;
21
21
import 'package:provider/provider.dart' ;
22
+ import 'package:wger/helpers/misc.dart' ;
22
23
import 'package:wger/models/nutrition/ingredient.dart' ;
23
24
import 'package:wger/models/nutrition/meal.dart' ;
24
25
import 'package:wger/models/nutrition/nutritional_goals.dart' ;
@@ -105,20 +106,25 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
105
106
// we also don't get an image when querying the API
106
107
// however, the typeahead suggestion does get an image, so we allow passing it...
107
108
108
- final url = context.read <NutritionPlansProvider >().baseProvider.auth.serverUrl;
109
+ final serverURL = context.read <NutritionPlansProvider >().baseProvider.auth.serverUrl;
109
110
110
- // TODO: display source name and source URL for an ingredient in the UI
111
111
showDialog (
112
112
context: context,
113
113
builder: (context) => FutureBuilder <Ingredient >(
114
114
future: Provider .of <NutritionPlansProvider >(context, listen: false ).fetchIngredient (id),
115
115
builder: (BuildContext context, AsyncSnapshot <Ingredient > snapshot) {
116
116
Ingredient ? ingredient;
117
117
NutritionalGoals ? goals;
118
+ String ? source;
119
+ String ? url;
118
120
119
121
if (snapshot.hasData) {
120
122
ingredient = snapshot.data;
121
123
goals = ingredient! .nutritionalValues.toGoals ();
124
+ source = ingredient.sourceName ?? 'unknown' ;
125
+ url = ingredient.remoteId == null
126
+ ? null
127
+ : 'https://world.openfoodfacts.org/product/${ingredient .remoteId }' ;
122
128
}
123
129
return AlertDialog (
124
130
title: (snapshot.hasData) ? Text (ingredient! .name) : null ,
@@ -128,7 +134,7 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
128
134
mainAxisSize: MainAxisSize .min,
129
135
children: [
130
136
if (image != null )
131
- CircleAvatar (backgroundImage: NetworkImage (url ! + image), radius: 128 ),
137
+ CircleAvatar (backgroundImage: NetworkImage (serverURL ! + image), radius: 128 ),
132
138
if (image != null ) const SizedBox (height: 12 ),
133
139
if (snapshot.hasError)
134
140
Text (
@@ -145,6 +151,15 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
145
151
showGperKg: false ,
146
152
),
147
153
),
154
+ if (snapshot.hasData && url == null ) Text ('Source: ${source !}' ),
155
+ if (snapshot.hasData && url != null )
156
+ Padding (
157
+ padding: const EdgeInsets .only (top: 12 ),
158
+ child: InkWell (
159
+ child: Text ('Source: ${source !}' ),
160
+ onTap: () => launchURL (url! , context),
161
+ ),
162
+ ),
148
163
],
149
164
),
150
165
),
0 commit comments