diff --git a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart index 7fb4b1542..e911b37da 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,12 @@ class RestoreFormPageState extends State { return null; } - FutureOr> _getSuggestions(pattern) { + FutureOr> _getSuggestions(String pattern, int itemIndex) { var suggestionList = WORDLIST.where((item) => item.startsWith(pattern)).toList(); + if (pattern.length == 4 && suggestionList.isNotEmpty) { + _selectSuggestion(suggestionList.first, itemIndex); + return List.empty(); + } return suggestionList.isNotEmpty ? suggestionList : List.empty(); } }