@@ -41,8 +41,7 @@ class MyHomePageState extends State<MyHomePage> {
41
41
bool readOnly = false ;
42
42
bool showSegmentedControl = true ;
43
43
final GlobalKey <FormBuilderState > _fbKey = GlobalKey <FormBuilderState >();
44
- final GlobalKey <FormFieldState > _specifyTextFieldKey =
45
- GlobalKey <FormFieldState >();
44
+ final GlobalKey <FormFieldState > _specifyTextFieldKey = GlobalKey <FormFieldState >();
46
45
47
46
ValueChanged _onChanged = (val) => print (val);
48
47
var genderOptions = ['Male' , 'Female' , 'Other' ];
@@ -74,16 +73,11 @@ class MyHomePageState extends State<MyHomePage> {
74
73
labelText: 'Select many options' ,
75
74
),
76
75
options: [
77
- FormBuilderFieldOption (
78
- value: 'Test' , child: Text ('Test' )),
79
- FormBuilderFieldOption (
80
- value: 'Test 1' , child: Text ('Test 1' )),
81
- FormBuilderFieldOption (
82
- value: 'Test 2' , child: Text ('Test 2' )),
83
- FormBuilderFieldOption (
84
- value: 'Test 3' , child: Text ('Test 3' )),
85
- FormBuilderFieldOption (
86
- value: 'Test 4' , child: Text ('Test 4' )),
76
+ FormBuilderFieldOption (value: 'Test' , child: Text ('Test' )),
77
+ FormBuilderFieldOption (value: 'Test 1' , child: Text ('Test 1' )),
78
+ FormBuilderFieldOption (value: 'Test 2' , child: Text ('Test 2' )),
79
+ FormBuilderFieldOption (value: 'Test 3' , child: Text ('Test 3' )),
80
+ FormBuilderFieldOption (value: 'Test 4' , child: Text ('Test 4' )),
87
81
],
88
82
),
89
83
FormBuilderChoiceChip (
@@ -92,16 +86,11 @@ class MyHomePageState extends State<MyHomePage> {
92
86
labelText: 'Select an option' ,
93
87
),
94
88
options: [
95
- FormBuilderFieldOption (
96
- value: 'Test' , child: Text ('Test' )),
97
- FormBuilderFieldOption (
98
- value: 'Test 1' , child: Text ('Test 1' )),
99
- FormBuilderFieldOption (
100
- value: 'Test 2' , child: Text ('Test 2' )),
101
- FormBuilderFieldOption (
102
- value: 'Test 3' , child: Text ('Test 3' )),
103
- FormBuilderFieldOption (
104
- value: 'Test 4' , child: Text ('Test 4' )),
89
+ FormBuilderFieldOption (value: 'Test' , child: Text ('Test' )),
90
+ FormBuilderFieldOption (value: 'Test 1' , child: Text ('Test 1' )),
91
+ FormBuilderFieldOption (value: 'Test 2' , child: Text ('Test 2' )),
92
+ FormBuilderFieldOption (value: 'Test 3' , child: Text ('Test 3' )),
93
+ FormBuilderFieldOption (value: 'Test 4' , child: Text ('Test 4' )),
105
94
],
106
95
),
107
96
FormBuilderCustomField (
@@ -116,17 +105,15 @@ class MyHomePageState extends State<MyHomePage> {
116
105
return InputDecorator (
117
106
decoration: InputDecoration (
118
107
labelText: "Select option" ,
119
- contentPadding:
120
- EdgeInsets .only (top: 10.0 , bottom: 0.0 ),
108
+ contentPadding: EdgeInsets .only (top: 10.0 , bottom: 0.0 ),
121
109
border: InputBorder .none,
122
110
errorText: field.errorText,
123
111
),
124
112
child: Container (
125
113
height: 200 ,
126
114
child: CupertinoPicker (
127
115
itemExtent: 30 ,
128
- children:
129
- allCountries.map ((c) => Text (c)).toList (),
116
+ children: allCountries.map ((c) => Text (c)).toList (),
130
117
onSelectedItemChanged: (index) {
131
118
print (index);
132
119
field.didChange (allCountries[index]);
@@ -156,19 +143,13 @@ class MyHomePageState extends State<MyHomePage> {
156
143
if (query.length != 0 ) {
157
144
var lowercaseQuery = query.toLowerCase ();
158
145
return contacts.where ((profile) {
159
- return profile.name
160
- .toLowerCase ()
161
- .contains (query.toLowerCase ()) ||
162
- profile.email
163
- .toLowerCase ()
164
- .contains (query.toLowerCase ());
146
+ return profile.name.toLowerCase ().contains (query.toLowerCase ()) ||
147
+ profile.email.toLowerCase ().contains (query.toLowerCase ());
165
148
}).toList (growable: false )
166
149
..sort ((a, b) => a.name
167
150
.toLowerCase ()
168
151
.indexOf (lowercaseQuery)
169
- .compareTo (b.name
170
- .toLowerCase ()
171
- .indexOf (lowercaseQuery)));
152
+ .compareTo (b.name.toLowerCase ().indexOf (lowercaseQuery)));
172
153
} else {
173
154
return const < Contact > [];
174
155
}
@@ -181,8 +162,7 @@ class MyHomePageState extends State<MyHomePage> {
181
162
backgroundImage: NetworkImage (profile.imageUrl),
182
163
),
183
164
onDeleted: () => state.deleteChip (profile),
184
- materialTapTargetSize:
185
- MaterialTapTargetSize .shrinkWrap,
165
+ materialTapTargetSize: MaterialTapTargetSize .shrinkWrap,
186
166
);
187
167
},
188
168
suggestionBuilder: (context, state, profile) {
@@ -274,8 +254,7 @@ class MyHomePageState extends State<MyHomePage> {
274
254
),
275
255
validators: [
276
256
FormBuilderValidators .requiredTrue (
277
- errorText:
278
- "You must accept terms and conditions to continue" ,
257
+ errorText: "You must accept terms and conditions to continue" ,
279
258
),
280
259
],
281
260
),
@@ -332,15 +311,12 @@ class MyHomePageState extends State<MyHomePage> {
332
311
if (query.length != 0 ) {
333
312
var lowercaseQuery = query.toLowerCase ();
334
313
return allCountries.where ((country) {
335
- return country
336
- .toLowerCase ()
337
- .contains (lowercaseQuery);
314
+ return country.toLowerCase ().contains (lowercaseQuery);
338
315
}).toList (growable: false )
339
316
..sort ((a, b) => a
340
317
.toLowerCase ()
341
318
.indexOf (lowercaseQuery)
342
- .compareTo (
343
- b.toLowerCase ().indexOf (lowercaseQuery)));
319
+ .compareTo (b.toLowerCase ().indexOf (lowercaseQuery)));
344
320
} else {
345
321
return allCountries;
346
322
}
@@ -364,35 +340,29 @@ class MyHomePageState extends State<MyHomePage> {
364
340
if (query.length != 0 ) {
365
341
var lowercaseQuery = query.toLowerCase ();
366
342
return contacts.where ((contact) {
367
- return contact.name
368
- .toLowerCase ()
369
- .contains (lowercaseQuery);
343
+ return contact.name.toLowerCase ().contains (lowercaseQuery);
370
344
}).toList (growable: false )
371
345
..sort ((a, b) => a.name
372
346
.toLowerCase ()
373
347
.indexOf (lowercaseQuery)
374
- .compareTo (b.name
375
- .toLowerCase ()
376
- .indexOf (lowercaseQuery)));
348
+ .compareTo (b.name.toLowerCase ().indexOf (lowercaseQuery)));
377
349
} else {
378
350
return contacts;
379
351
}
380
352
},
381
353
),
382
354
FormBuilderRadio (
383
- decoration:
384
- InputDecoration (labelText: 'My chosen language' ),
355
+ decoration: InputDecoration (labelText: 'My chosen language' ),
385
356
attribute: "best_language" ,
386
357
leadingInput: true ,
387
358
onChanged: _onChanged,
388
359
validators: [FormBuilderValidators .required ()],
389
- options:
390
- ["Dart" , "Kotlin" , "Java" , "Swift" , "Objective-C" ]
391
- .map ((lang) => FormBuilderFieldOption (
392
- value: lang,
393
- child: Text ('$lang ' ),
394
- ))
395
- .toList (growable: false ),
360
+ options: ["Dart" , "Kotlin" , "Java" , "Swift" , "Objective-C" ]
361
+ .map ((lang) => FormBuilderFieldOption (
362
+ value: lang,
363
+ child: Text ('$lang ' ),
364
+ ))
365
+ .toList (growable: false ),
396
366
),
397
367
FormBuilderRadio (
398
368
decoration: InputDecoration (labelText: 'Pick a number' ),
@@ -413,8 +383,7 @@ class MyHomePageState extends State<MyHomePage> {
413
383
],
414
384
),
415
385
FormBuilderSegmentedControl (
416
- decoration:
417
- InputDecoration (labelText: "Movie Rating (Archer)" ),
386
+ decoration: InputDecoration (labelText: "Movie Rating (Archer)" ),
418
387
attribute: "movie_rating" ,
419
388
textStyle: TextStyle (fontWeight: FontWeight .bold),
420
389
options: List .generate (5 , (i) => i + 1 )
@@ -456,8 +425,7 @@ class MyHomePageState extends State<MyHomePage> {
456
425
isHalfAllowed: true ,
457
426
),
458
427
FormBuilderCheckboxList (
459
- decoration: InputDecoration (
460
- labelText: "The language of my people" ),
428
+ decoration: InputDecoration (labelText: "The language of my people" ),
461
429
attribute: "languages" ,
462
430
initialValue: ["Dart" ],
463
431
leadingInput: true ,
@@ -473,21 +441,14 @@ class MyHomePageState extends State<MyHomePage> {
473
441
FormBuilderCustomField (
474
442
attribute: 'custom' ,
475
443
valueTransformer: (val) {
476
- if (val == "Other" )
477
- return _specifyTextFieldKey.currentState.value;
444
+ if (val == "Other" ) return _specifyTextFieldKey.currentState.value;
478
445
return val;
479
446
},
480
447
formField: FormField (
481
448
builder: (FormFieldState <String > field) {
482
- var languages = [
483
- "English" ,
484
- "Spanish" ,
485
- "Somali" ,
486
- "Other"
487
- ];
449
+ var languages = ["English" , "Spanish" , "Somali" , "Other" ];
488
450
return InputDecorator (
489
- decoration: InputDecoration (
490
- labelText: "What's your preferred language?" ),
451
+ decoration: InputDecoration (labelText: "What's your preferred language?" ),
491
452
child: Column (
492
453
children: languages
493
454
.map (
@@ -511,8 +472,7 @@ class MyHomePageState extends State<MyHomePage> {
511
472
SizedBox (width: 20 ),
512
473
Expanded (
513
474
child: TextFormField (
514
- key:
515
- _specifyTextFieldKey,
475
+ key: _specifyTextFieldKey,
516
476
),
517
477
),
518
478
],
@@ -539,6 +499,33 @@ class MyHomePageState extends State<MyHomePage> {
539
499
}
540
500
],
541
501
),
502
+ FormBuilderCountryPicker (
503
+ defaultSelectedCountryIsoCode: 'US' ,
504
+ attribute: "country" ,
505
+ cursorColor: Colors .black,
506
+ style: TextStyle (color: Colors .black, fontSize: 18 ),
507
+ priorityListByIsoCode: ['US' ],
508
+ valueTransformer: (value) {
509
+ return value.isoCode;
510
+ },
511
+ decoration: InputDecoration (border: OutlineInputBorder (), labelText: "Country" ),
512
+ validators: [
513
+ FormBuilderValidators .required (errorText: 'This field required.' ),
514
+ ],
515
+ ),
516
+ FormBuilderPhoneField (
517
+ attribute: 'phone_number' ,
518
+ keyboardType: TextInputType .phone,
519
+ defaultSelectedCountryIsoCode: 'US' ,
520
+ cursorColor: Colors .black,
521
+ style: TextStyle (color: Colors .black, fontSize: 18 ),
522
+ decoration: InputDecoration (border: OutlineInputBorder (), labelText: "Phone Number" ),
523
+ priorityListByIsoCode: ['US' ],
524
+ validators: [
525
+ FormBuilderValidators .numeric (errorText: 'Invalid phone number' ),
526
+ FormBuilderValidators .required (errorText: 'This field reqired' )
527
+ ],
528
+ ),
542
529
FormBuilderSignaturePad (
543
530
decoration: InputDecoration (labelText: "Signature" ),
544
531
attribute: "signature" ,
0 commit comments