我想在f用户点击时控制TextField
小部件。如何实现focusNode
属性?描述中没有详细的解释。
最佳答案
FocusNode focusNode;
void initState() {
focusNode = new FocusNode();
// listen to focus changes
focusNode.addListener(() => print('focusNode updated: hasFocus: ${focusNode.hasFocus}'));
}
void setFocus() {
FocusScope.of(context).requestFocus(focusNode);
}
Widget build() {
return
...
new TextField(focusNode: focusNode, ...);
}