@@ -99,6 +99,51 @@ See [pub.dev example tab](https://pub.dev/packages/flutter_form_builder/example)
99
99
100
100
### Specific uses
101
101
102
+ #### Validate and get values
103
+
104
+ ``` dart
105
+ final _formKey = GlobalKey<FormBuilderState>();
106
+
107
+ FormBuilder(
108
+ key: _formKey,
109
+ child: Column(
110
+ children: [
111
+ FormBuilderTextField(
112
+ key: _emailFieldKey,
113
+ name: 'email',
114
+ decoration: const InputDecoration(labelText: 'Email'),
115
+ validator: FormBuilderValidators.compose([
116
+ FormBuilderValidators.required(),
117
+ FormBuilderValidators.email(),
118
+ ]),
119
+ ),
120
+ const SizedBox(height: 10),
121
+ FormBuilderTextField(
122
+ name: 'password',
123
+ decoration: const InputDecoration(labelText: 'Password'),
124
+ obscureText: true,
125
+ validator: FormBuilderValidators.compose([
126
+ FormBuilderValidators.required(),
127
+ ]),
128
+ ),
129
+ MaterialButton(
130
+ color: Theme.of(context).colorScheme.secondary,
131
+ onPressed: () {
132
+ // Validate and save the form values
133
+ _formKey.currentState?.saveAndValidate();
134
+ debugPrint(_formKey.currentState?.value.toString());
135
+
136
+ // On another side, can access all field values without saving form with instantValues
137
+ _formKey.currentState?.validate();
138
+ debugPrint(_formKey.currentState?.instantValue.toString());
139
+ },
140
+ child: const Text('Login'),
141
+ )
142
+ ],
143
+ ),
144
+ ),
145
+ ```
146
+
102
147
#### Building your own custom field
103
148
104
149
To build your own field within a ` FormBuilder ` , we use ` FormBuilderField ` which will require that you define your own field.
0 commit comments