horshoo
horshoo
发布于 6个月前

flutter 输入框如何获得焦点,移除焦点

FocusNode mFocusNode = FocusNode();

...
TextField(
  focusNode: mFocusNode,
  ...
)

// 移除焦点
mFocusNode.unfocus();
// 获得焦点
FocusScope.of(context).requestFocus(mFocusNode);
// 是否获得焦点的状态
mFocusNode.hasFocus