diff --git a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart index 7fb4b1542..c000b6dd5 100644 --- a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart +++ b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart @@ -65,8 +65,9 @@ class RestoreFormPageState extends State { ), autovalidateMode: _autoValidateMode, validator: (text) => _onValidate(context, text!), - suggestionsCallback: _getSuggestions, + suggestionsCallback: (pattern) => _getSuggestions(pattern, itemIndex), hideOnEmpty: true, + hideOnLoading: true, autoFlipDirection: true, suggestionsBoxDecoration: const SuggestionsBoxDecoration( color: Colors.white, @@ -95,12 +96,7 @@ class RestoreFormPageState extends State { ), ); }, - onSuggestionSelected: (suggestion) { - widget.textEditingControllers[itemIndex].text = suggestion; - if (itemIndex + 1 < focusNodes.length) { - focusNodes[itemIndex + 1].requestFocus(); - } - }, + onSuggestionSelected: (suggestion) => _selectSuggestion(suggestion, itemIndex), ); }), ), @@ -108,6 +104,15 @@ class RestoreFormPageState extends State { ); } + Function _selectSuggestion(String suggestion, int itemIndex) { + return (suggestion) { + widget.textEditingControllers[itemIndex].text = suggestion; + if (itemIndex + 1 < focusNodes.length) { + focusNodes[itemIndex + 1].requestFocus(); + } + }; + } + String? _onValidate(BuildContext context, String text) { final texts = context.texts(); if (text.isEmpty) { @@ -119,8 +124,15 @@ class RestoreFormPageState extends State { return null; } - FutureOr> _getSuggestions(pattern) { + FutureOr> _getSuggestions(String pattern, int itemIndex) { var suggestionList = WORDLIST.where((item) => item.startsWith(pattern)).toList(); - return suggestionList.isNotEmpty ? suggestionList : List.empty(); + if (suggestionList.isNotEmpty && suggestionList.length == 1) { + widget.textEditingControllers[itemIndex].text = suggestionList.first; + if (itemIndex + 1 < focusNodes.length) { + focusNodes[itemIndex + 1].requestFocus(); + } + return List.empty(); + } + return suggestionList; } }