From 5b180a011fc8db1f01e021550349b292793692fd Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Mon, 17 Jul 2023 14:26:38 +0300 Subject: [PATCH 1/3] Autocomplete on restore form closes #505 --- .../mnemonics/widgets/restore_form.dart | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) 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(); } } From 3d522e2dde1b20e0c2f6d5c3c63369962d0cd993 Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Mon, 17 Jul 2023 18:07:10 +0300 Subject: [PATCH 2/3] Remove obsolete null check --- .../initial_walkthrough/mnemonics/widgets/restore_form.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart index e911b37da..0e87b2287 100644 --- a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart +++ b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart @@ -130,6 +130,6 @@ class RestoreFormPageState extends State { _selectSuggestion(suggestionList.first, itemIndex); return List.empty(); } - return suggestionList.isNotEmpty ? suggestionList : List.empty(); + return suggestionList; } } From 5bd5a35a8460291221355c3e817125bba8c47f42 Mon Sep 17 00:00:00 2001 From: Erdem Yerebasmaz Date: Wed, 4 Oct 2023 23:31:33 +0300 Subject: [PATCH 3/3] Auto select if there's a single suggestion remaining --- .../mnemonics/widgets/restore_form.dart | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart index 0e87b2287..c000b6dd5 100644 --- a/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart +++ b/lib/routes/initial_walkthrough/mnemonics/widgets/restore_form.dart @@ -126,8 +126,11 @@ class RestoreFormPageState extends State { 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); + 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;