Flutter controls a TextField to gain focus and lose focus
First, explain the usage scenario.
Click on a control to make the text box focus and pop up the input method.
We can directly use FocusScope.of(context).requestFocus() to achieve focus.
To achieve focus, you first need to define a FocusNode
FocusNode _commentFocus = FocusNode();
//在TextField中绑定
TextField(
focusNode: _commentFocus,
),
Get focus
Get focus When clicked, use FocusScope.of(context).requestFocus() to get focus
FocusScope.of(context).requestFocus(_commentFocus); // Get focus
Follow me and grow together!
-AsKai