Merge pull request #608 from cypherstack/ui-fixes

auto focus next field on correct seed word entry
This commit is contained in:
julian-CStack 2023-07-10 12:24:01 -06:00 committed by GitHub
commit 314f036dbf
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -98,6 +98,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
final List<TextEditingController> _controllers = []; final List<TextEditingController> _controllers = [];
final List<FormInputStatus> _inputStatuses = []; final List<FormInputStatus> _inputStatuses = [];
final List<FocusNode> _focusNodes = [];
late final BarcodeScannerInterface scanner; late final BarcodeScannerInterface scanner;
@ -151,6 +152,7 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
for (int i = 0; i < _seedWordCount; i++) { for (int i = 0; i < _seedWordCount; i++) {
_controllers.add(TextEditingController()); _controllers.add(TextEditingController());
_inputStatuses.add(FormInputStatus.empty); _inputStatuses.add(FormInputStatus.empty);
_focusNodes.add(FocusNode());
} }
super.initState(); super.initState();
@ -819,30 +821,43 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
i * 4 + j - 1 == 1 i * 4 + j - 1 == 1
? textSelectionControls ? textSelectionControls
: null, : null,
focusNode:
_focusNodes[i * 4 + j - 1],
onChanged: (value) { onChanged: (value) {
final FormInputStatus
formInputStatus;
if (value.isEmpty) { if (value.isEmpty) {
setState(() { formInputStatus =
_inputStatuses[
i * 4 + j - 1] =
FormInputStatus.empty; FormInputStatus.empty;
});
} else if (_isValidMnemonicWord( } else if (_isValidMnemonicWord(
value value
.trim() .trim()
.toLowerCase())) { .toLowerCase())) {
setState(() { formInputStatus =
_inputStatuses[
i * 4 + j - 1] =
FormInputStatus.valid; FormInputStatus.valid;
});
} else { } else {
setState(() { formInputStatus =
_inputStatuses[ FormInputStatus.invalid;
i * 4 + j - 1] =
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: controller:
_controllers[i * 4 + j - 1], _controllers[i * 4 + j - 1],
@ -914,26 +929,45 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
selectionControls: i == 1 selectionControls: i == 1
? textSelectionControls ? textSelectionControls
: null, : null,
focusNode: _focusNodes[i],
onChanged: (value) { onChanged: (value) {
final FormInputStatus
formInputStatus;
if (value.isEmpty) { if (value.isEmpty) {
setState(() { formInputStatus =
_inputStatuses[i] =
FormInputStatus.empty; FormInputStatus.empty;
});
} else if (_isValidMnemonicWord( } else if (_isValidMnemonicWord(
value value
.trim() .trim()
.toLowerCase())) { .toLowerCase())) {
setState(() { formInputStatus =
_inputStatuses[i] =
FormInputStatus.valid; FormInputStatus.valid;
});
} else { } else {
setState(() { formInputStatus =
_inputStatuses[i] = FormInputStatus.invalid;
}
if (formInputStatus ==
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], controller: _controllers[i],
@ -1034,24 +1068,34 @@ class _RestoreWalletViewState extends ConsumerState<RestoreWalletView> {
AutovalidateMode.onUserInteraction, AutovalidateMode.onUserInteraction,
selectionControls: selectionControls:
i == 1 ? textSelectionControls : null, i == 1 ? textSelectionControls : null,
focusNode: _focusNodes[i - 1],
onChanged: (value) { onChanged: (value) {
final FormInputStatus formInputStatus;
if (value.isEmpty) { if (value.isEmpty) {
setState(() { formInputStatus =
_inputStatuses[i - 1] =
FormInputStatus.empty; FormInputStatus.empty;
});
} else if (_isValidMnemonicWord( } else if (_isValidMnemonicWord(
value.trim().toLowerCase())) { value.trim().toLowerCase())) {
setState(() { formInputStatus =
_inputStatuses[i - 1] =
FormInputStatus.valid; FormInputStatus.valid;
});
} else { } else {
formInputStatus =
FormInputStatus.invalid;
}
if (formInputStatus ==
FormInputStatus.valid) {
if (i < _focusNodes.length) {
_focusNodes[i].requestFocus();
} else if (i == _focusNodes.length) {
_focusNodes[i - 1].unfocus();
}
}
setState(() { setState(() {
_inputStatuses[i - 1] = _inputStatuses[i - 1] =
FormInputStatus.invalid; formInputStatus;
}); });
}
}, },
controller: _controllers[i - 1], controller: _controllers[i - 1],
style: style: