![]() |
VOOZH | about |
There are many ways to submit user-input data in Flutter. But the most used way is using TextFields. But there is a drawback of using TextFields it requires controller of the every text field you create in Flutter. So to Overcome makes the use of Forms. Forms in flutter don't need any textController to store data. It just needs 1 GlobalKey which is set to FormState.
Note: The below code doesn't have a submit button as there is no requirement for it here. Readers can add their own functionality to the form and use the below code as a template.
Initialize the global key to a variable like _formKey here , because with this variable we can validate and save form.
Wrap the whole form with Form widget and give global key as key, because it creates a container for form fields.
Declare variables to store values of the form fields.
Store user input in respective variable.
The complete source code at : https://github.com/codec-akash/FormData
Output:
To know more about TextButton refer this article: Flutter – TextButton Widget