diff --git a/lib/widgets/nutrition/helpers.dart b/lib/widgets/nutrition/helpers.dart index 3fc47ca56..422616a5e 100644 --- a/lib/widgets/nutrition/helpers.dart +++ b/lib/widgets/nutrition/helpers.dart @@ -19,6 +19,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:provider/provider.dart'; +import 'package:wger/helpers/misc.dart'; import 'package:wger/models/nutrition/ingredient.dart'; import 'package:wger/models/nutrition/meal.dart'; import 'package:wger/models/nutrition/nutritional_goals.dart'; @@ -105,9 +106,8 @@ void showIngredientDetails(BuildContext context, int id, {String? 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 url = context.read().baseProvider.auth.serverUrl; + final serverURL = context.read().baseProvider.auth.serverUrl; -// TODO: display source name and source URL for an ingredient in the UI showDialog( context: context, builder: (context) => FutureBuilder( @@ -115,10 +115,16 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) { builder: (BuildContext context, AsyncSnapshot snapshot) { Ingredient? ingredient; NutritionalGoals? goals; + String? source; + String? url; if (snapshot.hasData) { ingredient = snapshot.data; goals = ingredient!.nutritionalValues.toGoals(); + source = ingredient.sourceName ?? 'unknown'; + url = ingredient.remoteId == null + ? null + : 'https://world.openfoodfacts.org/product/${ingredient.remoteId}'; } return AlertDialog( title: (snapshot.hasData) ? Text(ingredient!.name) : null, @@ -128,7 +134,7 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) { mainAxisSize: MainAxisSize.min, children: [ if (image != null) - CircleAvatar(backgroundImage: NetworkImage(url! + image), radius: 128), + CircleAvatar(backgroundImage: NetworkImage(serverURL! + image), radius: 128), if (image != null) const SizedBox(height: 12), if (snapshot.hasError) Text( @@ -145,6 +151,15 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) { showGperKg: false, ), ), + if (snapshot.hasData && url == null) Text('Source: ${source!}'), + if (snapshot.hasData && url != null) + Padding( + padding: const EdgeInsets.only(top: 12), + child: InkWell( + child: Text('Source: ${source!}'), + onTap: () => launchURL(url!, context), + ), + ), ], ), ),