Now a days in general we are filling online forms for applying any post in general govt or private sector. Forms are verified before submitting and if any field left blank that will also be notified when we submit the form. Today we are going to discuss validating the form by providing some input text field. If input is blank then it show please enter some value it displays as error message.
Creating a form with validation in Flutter:
Follow the below steps to create a form and validate it.
- Create a
Form
with aGlobalKey
- Add a
TextFormField
with validation logic - Create a button to validate and submit the for
By using GlobalKey
We are Create a Form
:
To create a form we are using Form
Widget and it acts as a container to group and validate multiple form fields.
we are using GlobalKey
. The Globalkey identify the Form
, and it allow us to validate the form in a later step.
The below code used to create a form with GlobalKey.