diff --git a/lib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart b/lib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart index f162c4f73..87219d277 100644 --- a/lib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart +++ b/lib/pages/add_wallet_views/restore_wallet_view/restore_wallet_view.dart @@ -98,6 +98,7 @@ class _RestoreWalletViewState extends ConsumerState { final List _controllers = []; final List _inputStatuses = []; + final List _focusNodes = []; late final BarcodeScannerInterface scanner; @@ -151,6 +152,7 @@ class _RestoreWalletViewState extends ConsumerState { for (int i = 0; i < _seedWordCount; i++) { _controllers.add(TextEditingController()); _inputStatuses.add(FormInputStatus.empty); + _focusNodes.add(FocusNode()); } super.initState(); @@ -819,30 +821,43 @@ class _RestoreWalletViewState extends ConsumerState { i * 4 + j - 1 == 1 ? textSelectionControls : null, + focusNode: + _focusNodes[i * 4 + j - 1], onChanged: (value) { + final FormInputStatus + formInputStatus; + if (value.isEmpty) { - setState(() { - _inputStatuses[ - i * 4 + j - 1] = - FormInputStatus.empty; - }); + formInputStatus = + FormInputStatus.empty; } else if (_isValidMnemonicWord( value .trim() .toLowerCase())) { - setState(() { - _inputStatuses[ - i * 4 + j - 1] = - FormInputStatus.valid; - }); + formInputStatus = + FormInputStatus.valid; } else { - setState(() { - _inputStatuses[ - i * 4 + j - 1] = - FormInputStatus - .invalid; - }); + formInputStatus = + FormInputStatus.invalid; } + + if (formInputStatus == + FormInputStatus.valid) { + if (i * 4 + j < + _focusNodes.length) { + _focusNodes[i * 4 + j] + .requestFocus(); + } else if (i * 4 + j == + _focusNodes.length) { + _focusNodes[i * 4 + j - 1] + .unfocus(); + } + } + setState(() { + _inputStatuses[i * 4 + + j - + 1] = formInputStatus; + }); }, controller: _controllers[i * 4 + j - 1], @@ -914,26 +929,45 @@ class _RestoreWalletViewState extends ConsumerState { selectionControls: i == 1 ? textSelectionControls : null, + focusNode: _focusNodes[i], onChanged: (value) { + final FormInputStatus + formInputStatus; + if (value.isEmpty) { - setState(() { - _inputStatuses[i] = - FormInputStatus.empty; - }); + formInputStatus = + FormInputStatus.empty; } else if (_isValidMnemonicWord( value .trim() .toLowerCase())) { - setState(() { - _inputStatuses[i] = - FormInputStatus.valid; - }); + formInputStatus = + FormInputStatus.valid; } else { - setState(() { - _inputStatuses[i] = + formInputStatus = + FormInputStatus.invalid; + } + + if (formInputStatus == FormInputStatus - .invalid; - }); + .valid && + (i - 1) < + _focusNodes.length) { + Focus.of(context) + .requestFocus( + _focusNodes[i]); + } + + if (formInputStatus == + FormInputStatus.valid) { + if (i + 1 < + _focusNodes.length) { + _focusNodes[i + 1] + .requestFocus(); + } else if (i + 1 == + _focusNodes.length) { + _focusNodes[i].unfocus(); + } } }, controller: _controllers[i], @@ -1034,24 +1068,34 @@ class _RestoreWalletViewState extends ConsumerState { AutovalidateMode.onUserInteraction, selectionControls: i == 1 ? textSelectionControls : null, + focusNode: _focusNodes[i - 1], onChanged: (value) { + final FormInputStatus formInputStatus; + if (value.isEmpty) { - setState(() { - _inputStatuses[i - 1] = - FormInputStatus.empty; - }); + formInputStatus = + FormInputStatus.empty; } else if (_isValidMnemonicWord( value.trim().toLowerCase())) { - setState(() { - _inputStatuses[i - 1] = - FormInputStatus.valid; - }); + formInputStatus = + FormInputStatus.valid; } else { - setState(() { - _inputStatuses[i - 1] = - FormInputStatus.invalid; - }); + formInputStatus = + FormInputStatus.invalid; } + + if (formInputStatus == + FormInputStatus.valid) { + if (i < _focusNodes.length) { + _focusNodes[i].requestFocus(); + } else if (i == _focusNodes.length) { + _focusNodes[i - 1].unfocus(); + } + } + setState(() { + _inputStatuses[i - 1] = + formInputStatus; + }); }, controller: _controllers[i - 1], style: