Forms
TextFormField, GlobalKey, and form validation
Flutter forms group input fields together for validation. Use Form, TextFormField, and GlobalKey to manage form state.
The Form widget groups TextFormFields and provides validation. Use a GlobalKey to access form state.
final _formKey = GlobalKey<FormState>();
Form(
key: _formKey,
child: Column(
children: [
TextFormField(...),
TextFormField(...),
ElevatedButton(
onPressed: () {
if (_formKey.currentState!.validate()) {
// Form is valid
}
},
),
],
),
)Sign Up Form
user@
abc123