英文:
How do I change the focus of the text field on Submit?
问题
我有一个文本字段,它有一个onSubmit方法,在其中我进行验证,然后聚焦到另一个字段,但出于某种原因,焦点不起作用。以下是代码部分的翻译:
onSubmitted: (value) {
//print("ga test");
if (!widget.validator?.call(value)) {
setState(() {
showError = true;
});
}
if (widget.nextFocus != null) {
FocusScope.of(context).requestFocus(widget.nextFocus);
}
},
英文:
I have a text field and it has an onSubmit method, inside which I check for validation and then focus on another field, but for some reason the focus does not work
onSubmitted: (value) {
//print("ga test");
if (!widget.validator?.call(value)) {
setState(() {
showError = true;
});
}
if (widget.nextFocus != null) {
FocusScope.of(context).requestFocus(widget.nextFocus);
}
},
答案1
得分: 0
我这样做了,而且它有效果:
if (widget.validator != null) {
setState(() {
showError = !widget.validator?.call(value);
});
}
if (widget.nextFocus != null) {
FocusScope.of(context).requestFocus(widget.nextFocus);
}
英文:
I did so and it worked
if (widget.validator != null) {
setState(() {
showError = !widget.validator?.call(value);
});
}
if (widget.nextFocus != null) {
FocusScope.of(context).requestFocus(widget.nextFocus);
}
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论