Drag a UI element

Create and style a text field

Build a form with validation

Cookbook

Forms

Build a form with validation

1. Create a Form with a GlobalKey

2. Add a TextFormField with validation logic

3. Create a button to validate and submit the form

How does this work?

Interactive example

Apps often require users to enter information into a text field.
For example, you might require users to log in with an email address
and password combination.

To make apps secure and easy to use, check whether the
information the user has provided is valid. If the user has correctly filled
out the form, process the information. If the user submits incorrect
information, display a friendly error message letting them know what went
wrong.

In this example, learn how to add validation to a form that has
a single text field using the following steps: