@@ -32,6 +32,7 @@ import 'package:wger/models/exercises/ingredient_api.dart';
32
32
import 'package:wger/models/nutrition/ingredient.dart' ;
33
33
import 'package:wger/models/nutrition/log.dart' ;
34
34
import 'package:wger/models/nutrition/nutritional_plan.dart' ;
35
+ import 'package:wger/models/nutrition/nutritional_values.dart' ;
35
36
import 'package:wger/providers/nutrition.dart' ;
36
37
import 'package:wger/widgets/core/core.dart' ;
37
38
import 'package:wger/widgets/nutrition/helpers.dart' ;
@@ -118,6 +119,11 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
118
119
}
119
120
return null ;
120
121
},
122
+ onChanged: (value) {
123
+ // if user changes the pattern, it means they want to drop the
124
+ // currently loaded ingredient (if any) and start a new search
125
+ widget._ingredientIdController.text = '' ;
126
+ },
121
127
decoration: InputDecoration (
122
128
prefixIcon: const Icon (Icons .search),
123
129
labelText: AppLocalizations .of (context).searchIngredient,
@@ -126,7 +132,8 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
126
132
);
127
133
},
128
134
suggestionsCallback: (pattern) {
129
- if (pattern == '' ) {
135
+ // don't do search if user has already loaded a specific item
136
+ if (pattern == '' || widget._ingredientIdController.text.isNotEmpty) {
130
137
return null ;
131
138
}
132
139
@@ -188,6 +195,7 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
188
195
}
189
196
final result = await Provider .of <NutritionPlansProvider >(context, listen: false )
190
197
.searchIngredientWithCode (barcode);
198
+ // TODO: show spinner...
191
199
if (! mounted) {
192
200
return ;
193
201
}
@@ -198,7 +206,16 @@ class _IngredientTypeaheadState extends State<IngredientTypeahead> {
198
206
builder: (ctx) => AlertDialog (
199
207
key: const Key ('found-dialog' ),
200
208
title: Text (AppLocalizations .of (context).productFound),
201
- content: Text (AppLocalizations .of (context).productFoundDescription (result.name)),
209
+ content: Column (
210
+ mainAxisSize: MainAxisSize .min,
211
+ children: [
212
+ Text (AppLocalizations .of (context).productFoundDescription (result.name)),
213
+ MealItemTile (
214
+ ingredient: result,
215
+ nutritionalValues: result.nutritionalValues,
216
+ ),
217
+ ],
218
+ ),
202
219
actions: [
203
220
TextButton (
204
221
key: const Key ('found-dialog-confirm-button' ),
@@ -357,3 +374,23 @@ class IngredientAvatar extends StatelessWidget {
357
374
: const CircleIconAvatar (Icon (Icons .image, color: Colors .grey));
358
375
}
359
376
}
377
+
378
+ class MealItemTile extends StatelessWidget {
379
+ final Ingredient ingredient;
380
+ final NutritionalValues nutritionalValues;
381
+
382
+ const MealItemTile ({
383
+ super .key,
384
+ required this .ingredient,
385
+ required this .nutritionalValues,
386
+ });
387
+
388
+ @override
389
+ Widget build (BuildContext context) {
390
+ return ListTile (
391
+ leading: IngredientAvatar (ingredient: ingredient),
392
+ title: Text (getShortNutritionValues (nutritionalValues, context)),
393
+ subtitle: Text (ingredient.id.toString ()),
394
+ );
395
+ }
396
+ }
0 commit comments