@@ -8,7 +8,6 @@ import 'package:collection/collection.dart';
88import 'package:model/ingredient.dart' ;
99import 'package:model/recipe.dart' ;
1010import 'package:common/extensions.dart' ;
11- import 'package:weekly_menu_app/widgets/shared/flutter_data_state_builder.dart' ;
1211
1312import '../../../shared/base_dialog.dart' ;
1413import '../../../shared/empty_page_placeholder.dart' ;
@@ -102,7 +101,7 @@ class RecipeIngredientsTab extends HookConsumerWidget {
102101 }
103102}
104103
105- class _RecipeIngredientListTileWrapper extends HookConsumerWidget {
104+ class _RecipeIngredientListTileWrapper extends StatelessWidget {
106105 final RecipeIngredient ? recipeIngredient;
107106 final bool editEnabled;
108107 final bool autofocus;
@@ -123,7 +122,7 @@ class _RecipeIngredientListTileWrapper extends HookConsumerWidget {
123122 : super (key: key);
124123
125124 @override
126- Widget build (BuildContext context, WidgetRef ref ) {
125+ Widget build (BuildContext context) {
127126 if (recipeIngredient != null ) {
128127 return _RecipeIngredientListTile (
129128 key: ValueKey (recipeIngredient! .ingredientName),
@@ -357,63 +356,57 @@ class _IngredientSuggestionTextField extends HookConsumerWidget {
357356 final hasFocus = useState (false );
358357 final hasText = useState (false );
359358
360- final ingredientsStream = ref.read (ingredientsRepositoryProvider).stream ();
361-
362- return RepositoryStreamBuilder <List <Ingredient >>(
363- stream: ingredientsStream,
364- builder: (context, model) {
365- return Autocomplete <Ingredient >(
366- initialValue:
367- TextEditingValue (text: recipeIngredient? .ingredientName ?? '' ),
368- optionsMaxHeight: 100 ,
369- optionsBuilder: (textEditingValue) async {
370- if (textEditingValue.text.length < suggestAfter ||
371- ! enabled ||
372- textEditingValue.text == recipeIngredient? .ingredientName)
373- return const < Ingredient > [];
374-
375- return model.where ((i) => i.name
376- .toLowerCase ()
377- .contains (textEditingValue.text.toLowerCase ()));
378- },
379- displayStringForOption: (option) => option.name,
380- fieldViewBuilder:
381- (context, textEditingController, focusNode, onFieldSubmitted) {
382- focusNode.addListener (() {
383- hasFocus.value = focusNode.hasPrimaryFocus;
384-
385- if (! focusNode.hasPrimaryFocus) {
386- textEditingController.text =
387- recipeIngredient? .ingredientName ?? '' ;
388- textEditingController.selection = TextSelection .fromPosition (
389- TextPosition (offset: textEditingController.text.length));
390- }
391-
392- onFocusChanged? .call (focusNode.hasPrimaryFocus);
393- });
394-
395- return AutoSizeTextField (
396- scrollController: scrollController,
397- autofocus: autofocus,
398- focusNode: enabled ? focusNode : null ,
399- textCapitalization: TextCapitalization .sentences,
400- controller: textEditingController,
401- onChanged: (text) {
402- hasText.value = text.isNotBlank;
403- },
404- readOnly: ! enabled,
405- decoration: InputDecoration (
406- border: InputBorder .none,
407- suffixIcon: _buildSuffixIcon (
408- ref,
409- editEnabled: enabled,
410- hasFocus: hasFocus.value,
411- hasText: hasText.value,
412- controller: textEditingController,
413- )),
414- onSubmitted: (text) => _submit (ref, text));
415- },
416- );
359+ return Autocomplete <Ingredient >(
360+ initialValue:
361+ TextEditingValue (text: recipeIngredient? .ingredientName ?? '' ),
362+ optionsMaxHeight: 100 ,
363+ optionsBuilder: (textEditingValue) async {
364+ if (textEditingValue.text.length < suggestAfter ||
365+ ! enabled ||
366+ textEditingValue.text == recipeIngredient? .ingredientName)
367+ return const < Ingredient > [];
368+
369+ final ingredientsStream = await ref.read (ingredientsRepositoryProvider).loadAll ();
370+ return ingredientsStream.where ((i) => i.name
371+ .toLowerCase ()
372+ .contains (textEditingValue.text.toLowerCase ()));
373+ },
374+ displayStringForOption: (option) => option.name,
375+ fieldViewBuilder:
376+ (context, textEditingController, focusNode, onFieldSubmitted) {
377+ focusNode.addListener (() {
378+ hasFocus.value = focusNode.hasPrimaryFocus;
379+
380+ if (! focusNode.hasPrimaryFocus) {
381+ textEditingController.text =
382+ recipeIngredient? .ingredientName ?? '' ;
383+ textEditingController.selection = TextSelection .fromPosition (
384+ TextPosition (offset: textEditingController.text.length));
385+ }
386+
387+ onFocusChanged? .call (focusNode.hasPrimaryFocus);
388+ });
389+
390+ return AutoSizeTextField (
391+ scrollController: scrollController,
392+ autofocus: autofocus,
393+ focusNode: enabled ? focusNode : null ,
394+ textCapitalization: TextCapitalization .sentences,
395+ controller: textEditingController,
396+ onChanged: (text) {
397+ hasText.value = text.isNotBlank;
398+ },
399+ readOnly: ! enabled,
400+ decoration: InputDecoration (
401+ border: InputBorder .none,
402+ suffixIcon: _buildSuffixIcon (
403+ ref,
404+ editEnabled: enabled,
405+ hasFocus: hasFocus.value,
406+ hasText: hasText.value,
407+ controller: textEditingController,
408+ )),
409+ onSubmitted: (text) => _submit (ref, text));
417410 },
418411 );
419412 }
0 commit comments