[英]Slide focus to TextField in Flutter
I have been learning flutter for last few days and I encountered a problem while developing my app.最近几天我一直在学习 flutter,我在开发我的应用程序时遇到了一个问题。 So I have a basic form containing all the basic input fields and after a user clicks the submit button the app checks for the validity of the text field.
所以我有一个包含所有基本输入字段的基本表单,在用户单击提交按钮后,应用程序检查文本字段的有效性。 If there is some wrong entry the app moves focus back to the text field.
如果输入错误,应用程序会将焦点移回文本字段。
How can I move focus back to the Text Field?如何将焦点移回文本字段?
var focusNode = FocusNode();
var textField = TextField(focusNode: focusNode);
FocusScope.of(context).requestFocus(focusNode);
// or
focusNode.requestFocus();
See also另见
TextField(
autofocus: true,
);
FocusNode name_focus = FocusNode(); FocusNode name_focus = FocusNode();
TextField(
controller: name_Controller,
focusNode: name_focus,
decoration: InputDecoration(
errorText: name_validate ? 'Enter Name' : null,
labelStyle:
TextStyle(color: HexColor(HexColor.gray_text)),
labelText: "Name",
border: OutlineInputBorder(),
enabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: HexColor(HexColor.gray))),
focusedBorder: OutlineInputBorder(
borderSide:
BorderSide(color: HexColor(HexColor.gray))),
),
),
check validation name is not empty automatic scroll my page for show检查验证名称是否为空自动滚动我的页面以供显示
if(name_Controller.text.isEmpty){
name_validate=true;
name_focus.requestFocus();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.