auto focus next field on correct seed word entry

This commit is contained in:
julian 2023-07-10 10:05:30 -06:00
parent aa026ef33c
commit 593680f9f3

View file

@ -98,6 +98,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
final List<TextEditingController> _controllers = [];
final List<FormInputStatus> _inputStatuses = [];
final List<FocusNode> _focusNodes = [];
late final BarcodeScannerInterface scanner;
@ -151,6 +152,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
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<RestoreWalletView> {
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<RestoreWalletView> {
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<RestoreWalletView> {
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: