Skip to content

Commit 1ae3f33

Browse files
committed
use ingredient.license_object_url to link to human readable page
1 parent d99ca41 commit 1ae3f33

File tree

3 files changed

+13
-9
lines changed

3 files changed

+13
-9
lines changed

lib/models/nutrition/ingredient.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ part 'ingredient.g.dart';
2626
class Ingredient {
2727
// fields returned by django api that we ignore here:
2828
// uuid, last_updated, last_imported, weight_units, language
29-
// all license fields
29+
// most license fields
3030

3131
@JsonKey(required: true)
3232
final int id;
@@ -42,6 +42,9 @@ class Ingredient {
4242
@JsonKey(required: true, name: 'source_url')
4343
final String? sourceUrl;
4444

45+
@JsonKey(required: true, name: 'license_object_url')
46+
final String? licenseObjectURl;
47+
4548
/// Barcode of the product
4649
@JsonKey(required: true)
4750
final String? code;
@@ -91,6 +94,7 @@ class Ingredient {
9194
required this.remoteId,
9295
required this.sourceName,
9396
required this.sourceUrl,
97+
this.licenseObjectURl,
9498
required this.id,
9599
required this.code,
96100
required this.name,

lib/models/nutrition/ingredient.g.dart

Lines changed: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/widgets/nutrition/helpers.dart

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,11 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
110110
Ingredient? ingredient;
111111
NutritionalGoals? goals;
112112
String? source;
113-
String? url;
114113

115114
if (snapshot.hasData) {
116115
ingredient = snapshot.data;
117116
goals = ingredient!.nutritionalValues.toGoals();
118117
source = ingredient.sourceName ?? 'unknown';
119-
url = ingredient.remoteId == null
120-
? null
121-
: 'https://world.openfoodfacts.org/product/${ingredient.remoteId}';
122118
}
123119
return AlertDialog(
124120
title: (snapshot.hasData) ? Text(ingredient!.name) : null,
@@ -131,7 +127,7 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
131127
if (image != null) const SizedBox(height: 12),
132128
if (snapshot.hasError)
133129
Text(
134-
'Ingredient lookup error: ${snapshot.error}',
130+
'Ingredient lookup error: ${snapshot.error ?? 'unknown error'}',
135131
style: const TextStyle(color: Colors.red),
136132
),
137133
if (!snapshot.hasData && !snapshot.hasError) const CircularProgressIndicator(),
@@ -144,13 +140,14 @@ void showIngredientDetails(BuildContext context, int id, {String? image}) {
144140
showGperKg: false,
145141
),
146142
),
147-
if (snapshot.hasData && url == null) Text('Source: ${source!}'),
148-
if (snapshot.hasData && url != null)
143+
if (snapshot.hasData && ingredient!.licenseObjectURl == null)
144+
Text('Source: ${source!}'),
145+
if (snapshot.hasData && ingredient!.licenseObjectURl != null)
149146
Padding(
150147
padding: const EdgeInsets.only(top: 12),
151148
child: InkWell(
152149
child: Text('Source: ${source!}'),
153-
onTap: () => launchURL(url!, context),
150+
onTap: () => launchURL(ingredient!.licenseObjectURl!, context),
154151
),
155152
),
156153
],

0 commit comments

Comments
 (0)