@@ -42,7 +42,7 @@ class _CompleteFormState extends State<CompleteForm> {
42
42
'best_language' : 'Dart' ,
43
43
'age' : '13' ,
44
44
'gender' : 'Male' ,
45
- 'languages_filter' : ['Dart' ]
45
+ 'languages_filter' : ['Dart' ],
46
46
},
47
47
skipDisabled: true ,
48
48
child: Column (
@@ -78,8 +78,9 @@ class _CompleteFormState extends State<CompleteForm> {
78
78
suffixIcon: IconButton (
79
79
icon: const Icon (Icons .close),
80
80
onPressed: () {
81
- _formKey.currentState! .fields['date_range' ]
82
- ? .didChange (null );
81
+ _formKey.currentState! .fields['date_range' ]? .didChange (
82
+ null ,
83
+ );
83
84
},
84
85
),
85
86
),
@@ -89,6 +90,20 @@ class _CompleteFormState extends State<CompleteForm> {
89
90
validator: FormBuilderValidators .compose ([
90
91
FormBuilderValidators .min (6 ),
91
92
]),
93
+ errorBuilder: (context, errorText) => TextButton (
94
+ onPressed: () {
95
+ ScaffoldMessenger .of (context).showSnackBar (
96
+ SnackBar (
97
+ content: Text (errorText),
98
+ duration: const Duration (seconds: 2 ),
99
+ ),
100
+ );
101
+ },
102
+ child: Text (
103
+ errorText,
104
+ style: const TextStyle (color: Colors .red),
105
+ ),
106
+ ),
92
107
onChanged: _onChanged,
93
108
min: 0.0 ,
94
109
max: 10.0 ,
@@ -109,9 +124,9 @@ class _CompleteFormState extends State<CompleteForm> {
109
124
divisions: 20 ,
110
125
maxValueWidget: (max) => TextButton (
111
126
onPressed: () {
112
- _formKey.currentState? .patchValue (
113
- { 'range_slider' : const RangeValues (4 , 100 )} ,
114
- );
127
+ _formKey.currentState? .patchValue ({
128
+ 'range_slider' : const RangeValues (4 , 100 ),
129
+ } );
115
130
},
116
131
child: Text (max),
117
132
),
@@ -186,21 +201,24 @@ class _CompleteFormState extends State<CompleteForm> {
186
201
: const Icon (Icons .check),
187
202
hintText: 'Select Gender' ,
188
203
),
189
- validator: FormBuilderValidators .compose (
190
- [FormBuilderValidators .required ()]),
204
+ validator: FormBuilderValidators .compose ([
205
+ FormBuilderValidators .required (),
206
+ ]),
191
207
items: genderOptions
192
- .map ((gender) => DropdownMenuItem (
193
- alignment: AlignmentDirectional .center,
194
- value: gender,
195
- child: Text (gender),
196
- ))
208
+ .map (
209
+ (gender) => DropdownMenuItem (
210
+ alignment: AlignmentDirectional .center,
211
+ value: gender,
212
+ child: Text (gender),
213
+ ),
214
+ )
197
215
.toList (),
198
216
onChanged: (val) {
199
217
setState (() {
200
- _genderHasError = ! (_formKey
201
- .currentState? .fields['gender' ]
202
- ? .validate () ??
203
- false );
218
+ _genderHasError =
219
+ ! (_formKey .currentState? .fields['gender' ]
220
+ ? .validate () ??
221
+ false );
204
222
});
205
223
},
206
224
valueTransformer: (val) => val? .toString (),
@@ -212,13 +230,16 @@ class _CompleteFormState extends State<CompleteForm> {
212
230
initialValue: null ,
213
231
name: 'best_language' ,
214
232
onChanged: _onChanged,
215
- validator: FormBuilderValidators .compose (
216
- [FormBuilderValidators .required ()]),
233
+ validator: FormBuilderValidators .compose ([
234
+ FormBuilderValidators .required (),
235
+ ]),
217
236
options: ['Dart' , 'Kotlin' , 'Java' , 'Swift' , 'Objective-C' ]
218
- .map ((lang) => FormBuilderFieldOption (
219
- value: lang,
220
- child: Text (lang),
221
- ))
237
+ .map (
238
+ (lang) => FormBuilderFieldOption (
239
+ value: lang,
240
+ child: Text (lang),
241
+ ),
242
+ )
222
243
.toList (growable: false ),
223
244
controlAffinity: ControlAffinity .trailing,
224
245
),
@@ -231,7 +252,8 @@ class _CompleteFormState extends State<CompleteForm> {
231
252
FormBuilderCheckboxGroup <String >(
232
253
autovalidateMode: AutovalidateMode .onUserInteraction,
233
254
decoration: const InputDecoration (
234
- labelText: 'The language of my people' ),
255
+ labelText: 'The language of my people' ,
256
+ ),
235
257
name: 'languages' ,
236
258
// initialValue: const ['Dart'],
237
259
options: const [
@@ -255,7 +277,8 @@ class _CompleteFormState extends State<CompleteForm> {
255
277
FormBuilderFilterChips <String >(
256
278
autovalidateMode: AutovalidateMode .onUserInteraction,
257
279
decoration: const InputDecoration (
258
- labelText: 'The language of my people' ),
280
+ labelText: 'The language of my people' ,
281
+ ),
259
282
name: 'languages_filter' ,
260
283
selectedColor: Colors .red,
261
284
options: const [
@@ -289,8 +312,9 @@ class _CompleteFormState extends State<CompleteForm> {
289
312
FormBuilderChoiceChips <String >(
290
313
autovalidateMode: AutovalidateMode .onUserInteraction,
291
314
decoration: const InputDecoration (
292
- labelText:
293
- 'Ok, if I had to choose one language, it would be:' ),
315
+ labelText:
316
+ 'Ok, if I had to choose one language, it would be:' ,
317
+ ),
294
318
name: 'languages_choice' ,
295
319
initialValue: 'Dart' ,
296
320
options: const [
@@ -325,15 +349,16 @@ class _CompleteFormState extends State<CompleteForm> {
325
349
children: < Widget > [
326
350
Expanded (
327
351
child: ElevatedButton (
328
- onPressed: () {
329
- if (_formKey.currentState? .saveAndValidate () ?? false ) {
330
- debugPrint (_formKey.currentState? .value.toString ());
331
- } else {
332
- debugPrint (_formKey.currentState? .value.toString ());
333
- debugPrint ('validation failed' );
334
- }
335
- },
336
- child: const Text ('Submit' )),
352
+ onPressed: () {
353
+ if (_formKey.currentState? .saveAndValidate () ?? false ) {
354
+ debugPrint (_formKey.currentState? .value.toString ());
355
+ } else {
356
+ debugPrint (_formKey.currentState? .value.toString ());
357
+ debugPrint ('validation failed' );
358
+ }
359
+ },
360
+ child: const Text ('Submit' ),
361
+ ),
337
362
),
338
363
const SizedBox (width: 20 ),
339
364
Expanded (
0 commit comments