Focus a text field when a button is tapped

Rather than immediately shifting focus to a specific text field,
you might need to give focus to a text field at a later point in time.
In the real world, you might also need to give focus to a specific
text field in response to an API call or a validation error.
In this example, give focus to a text field after the user
presses a button using the following steps:

Create a FocusNode.

Pass the FocusNode to a TextField.

Give focus to the TextField when a button is tapped.

1. Create a FocusNode

First, create a FocusNode.
Use the FocusNode to identify a specific TextField in Flutter’s
“focus tree.” This allows you to give focus to the TextField
in the next steps.