Create a Form with a GlobalKey.

Add a TextFormField with validation logic.

Create a button to validate and submit the form.

1. Create a Form with a GlobalKey

First, create a Form.
The Form widget acts as a container for grouping
and validating multiple form fields.

When creating the form, provide a GlobalKey.
This uniquely identifies the Form,
and allows validation of the form in a later step.

Tip:
  Using a GlobalKey is the recommended way to access a form.
  However, if you have a more complex widget tree,
  you can use the Form.of() method to
  access the form within nested widgets.

2. Add a TextFormField with validation logic