英文:
How to avoid focusnode use in textformfield in flutter?
问题
我已经使用focusNode
来将光标焦点放在文本表单字段上。但我定义了一个全局的textformfield
小部件,但只在单个屏幕上使用了focus node
。现在的问题是,由于小部件中的通用focusnode
,自动激活了所有字段的光标。我们如何设置仅在登录屏幕中focus node
才能工作,否则将避免该条件。
FocusNode textFocusOnFirstField = FocusNode();
TextFormField(
// 在所有的TextFormField中使用这个变量
// enabled: isEnable, // 在所有的TextFormField中使用这个变量
focusNode: textFocusOnFirstField,
readOnly: readOnly,
)
英文:
I have used focusNode to focus cursor on text form field. But I defined global textformfield widget. but used focus node in single screen only. Now the problem is automatically all the field cursor gets activated. because of that common focusnode in widget. How we can set that only in slogin screen focus node will work or else that condition will avoid.
FocusNode textFocusOnFirstField = FocusNode();
TextFormField(
// here use the variable in all the TextFormField
// enabled: isEnable, // here use the variable in all the TextFormField
focusNode: textFocusOnFirstField ,
readOnly: readOnly,
答案1
得分: 1
使用以下代码在initState()
中,以便在屏幕加载时取消所有文本字段的焦点:
FocusScope.of(context).unfocus();
英文:
FocusScope.of(context).unfocus();
Use this in initState() so that it unfocuses all the textfield as soon as screen loads.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论