You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
[](https://www.youtube.com/watch?v=7FBELQq808M)
12
15
13
16
[Check out the video tutorial from SyntacOps on Youtube](https://www.youtube.com/watch?v=7FBELQq808M)
14
17
15
18
## Simple Usage
19
+
16
20
To use this plugin, add `flutter_form_builder` as a [dependency in your pubspec.yaml file](https://flutter.io/platform-plugins/).
17
21
18
-
- For Flutter 1.17.x, use version 3.12.x
19
-
- For Flutter 1.20.x, use version 3.13.x
20
-
- For Flutter 1.22.X, use version 3.14.x
22
+
- For Flutter 1.17.x, use version 3.12.x
23
+
- For Flutter 1.20.x, use version 3.13.x
24
+
- For Flutter 1.22.X, use version 3.14.x
21
25
22
26
### Example
27
+
23
28
```dart
24
29
final GlobalKey<FormBuilderState> _fbKey = GlobalKey<FormBuilderState>();
25
30
```
31
+
26
32
**Note:** Avoid defining the GlobalKey inside your build method because this will create a new GlobalKey on every build cycle bringing about some erratic behavior.
27
33
28
34
**Note:** If you use FormBuilderDateTimePicker
35
+
29
36
```dart
30
37
import 'package:intl/intl.dart';
31
38
```
32
39
33
-
34
40
```dart
35
41
Column(
36
42
children: <Widget>[
@@ -204,49 +210,54 @@ Column(
204
210
```
205
211
206
212
## Input widgets
213
+
207
214
The currently supported fields include:
208
-
*`FormBuilderCheckbox` - Single Checkbox field
209
-
*~~`FormBuilderCheckboxList`~~ - List of Checkboxes for multiple selection with options listed vertically.
210
-
*`FormBuilderCheckboxGroup` - List of Checkboxes for multiple selection. Unlike in `FormBuilderCheckboxList`, options can either be shown vertically or horizontally.
211
-
*`FormBuilderChipsInput` - Takes a list of `Chip`s as input and suggests more options on typing
212
-
*`FormBuilderChoiceChip` - Creates a chip that acts like a radio button.
213
-
*`FormBuilderColorPicker` - For `Color` input selection
214
-
*`FormBuilderCountryPicker` - Country selection from list
215
-
*`FormBuilderDateRangePicker` - For selection of a range of dates
216
-
*`FormBuilderDateTimePicker` - For `Date`, `Time` and `DateTime` input
217
-
*`FormBuilderDropdown` - Used to select one value from a list as a Dropdown
218
-
*`FormBuilderFilterChip` - Creates a chip that acts like a checkbox.
219
-
*`FormBuilderImagePicker` - Picker a image from Gallery or Camera and stores it in a List of images, File or String. **Note**: This picker is available for iOS and Android.
220
-
*`FormBuilderPhoneField` - International phone number input.
221
-
*~~`FormBuilderRadio`~~ - Used to select one value from a list of Radio Widgets listed vertically.
222
-
*`FormBuilderRadioGroup` - Used to select one value from a list of Radio Widgets. Unlike in `FormBuilderRadio`, options can either be shown vertically or horizontally.
223
-
*`FormBuilderRangeSlider` - Used to select a range from a range of values
224
-
*`FormBuilderRate` - For selection of a numerical value as a rating
225
-
*`FormBuilderSegmentedControl` - For selection of a value from the `CupertinoSegmentedControl` as an input
226
-
*`FormBuilderSignaturePad` - Presents a drawing pad on which user can doodle
227
-
*`FormBuilderSlider` - For selection of a numerical value on a slider
228
-
*~~`FormBuilderStepper`~~ - Selection of a number by tapping on a plus or minus symbol. Deprecated; replaced with `FormBuilderTouchSpin`
229
-
*`FormBuilderSwitch` - On/Off switch
230
-
*`FormBuilderTextField` - For text input. Accepts input of single-line text, multi-line text, password, email, urls etc by using different configurations and validators
231
-
*`FormBuilderTouchSpin` - Selection of a number by tapping on a plus or minus icon
232
-
*`FormBuilderTypeAhead` - Auto-completes user input from a list of items
215
+
216
+
-`FormBuilderCheckbox` - Single Checkbox field
217
+
-~~`FormBuilderCheckboxList`~~ - List of Checkboxes for multiple selection with options listed vertically.
218
+
-`FormBuilderCheckboxGroup` - List of Checkboxes for multiple selection. Unlike in `FormBuilderCheckboxList`, options can either be shown vertically or horizontally.
219
+
-`FormBuilderChipsInput` - Takes a list of `Chip`s as input and suggests more options on typing
220
+
-`FormBuilderChoiceChip` - Creates a chip that acts like a radio button.
221
+
-`FormBuilderColorPicker` - For `Color` input selection
222
+
-`FormBuilderCountryPicker` - Country selection from list
223
+
-`FormBuilderDateRangePicker` - For selection of a range of dates
224
+
-`FormBuilderDateTimePicker` - For `Date`, `Time` and `DateTime` input
225
+
-`FormBuilderDropdown` - Used to select one value from a list as a Dropdown
226
+
-`FormBuilderFilterChip` - Creates a chip that acts like a checkbox.
227
+
-`FormBuilderImagePicker` - Picker a image from Gallery or Camera and stores it in a List of images, File or String. **Note**: This picker is available for iOS and Android.
228
+
-`FormBuilderPhoneField` - International phone number input.
229
+
-~~`FormBuilderRadio`~~ - Used to select one value from a list of Radio Widgets listed vertically.
230
+
-`FormBuilderRadioGroup` - Used to select one value from a list of Radio Widgets. Unlike in `FormBuilderRadio`, options can either be shown vertically or horizontally.
231
+
-`FormBuilderRangeSlider` - Used to select a range from a range of values
232
+
-`FormBuilderRate` - For selection of a numerical value as a rating
233
+
-`FormBuilderSegmentedControl` - For selection of a value from the `CupertinoSegmentedControl` as an input
234
+
-`FormBuilderSignaturePad` - Presents a drawing pad on which user can doodle
235
+
-`FormBuilderSlider` - For selection of a numerical value on a slider
236
+
-~~`FormBuilderStepper`~~ - Selection of a number by tapping on a plus or minus symbol. Deprecated; replaced with `FormBuilderTouchSpin`
237
+
-`FormBuilderSwitch` - On/Off switch
238
+
-`FormBuilderTextField` - For text input. Accepts input of single-line text, multi-line text, password, email, urls etc by using different configurations and validators
239
+
-`FormBuilderTouchSpin` - Selection of a number by tapping on a plus or minus icon
240
+
-`FormBuilderTypeAhead` - Auto-completes user input from a list of items
233
241
234
242
In order to create an input field in the form, along with the label, and any applicable validation, there are several attributes that are supported by all types of inputs namely:
|`attribute`|`String`|`null`|`true`| This will form the key in the form value Map |
239
-
|`initialValue`|`dynamic`|`null`|`false`| The initial value of the input field |
240
-
|`readOnly`|`bool`|`false`|`false`| Determines whether the field widget will accept user input. This value will be ignored if the `readOnly` attribute of `FormBuilder` widget is set to `true`|
|`validators`|`List<FormFieldValidator>`|`[]`|`false`| List of `FormFieldValidator`s that will check the validity of value candidate in the `FormField`|
243
-
|`onChanged`|`ValueChanged<T>`|`null`|`false`| This event function will fire immediately the the field value changes |
244
-
|`valueTransformer`|`ValueTransformer<T>`|`null`|`false`| Function that transforms field value before saving to form value. e.g. transform TextField value for numeric field from `String` to `num`|
|`attribute`|`String`|`null`|`true`| This will form the key in the form value Map |
247
+
|`initialValue`|`dynamic`|`null`|`false`| The initial value of the input field |
248
+
|`readOnly`|`bool`|`false`|`false`| Determines whether the field widget will accept user input. This value will be ignored if the `readOnly` attribute of `FormBuilder` widget is set to `true`|
|`validators`|`List<FormFieldValidator>`|`[]`|`false`| List of `FormFieldValidator`s that will check the validity of value candidate in the `FormField`|
251
+
|`onChanged`|`ValueChanged<T>`|`null`|`false`| This event function will fire immediately the the field value changes |
252
+
|`valueTransformer`|`ValueTransformer<T>`|`null`|`false`| Function that transforms field value before saving to form value. e.g. transform TextField value for numeric field from `String` to `num`|
253
+
245
254
The rest of the attributes will be determined by the type of Widget being used.
246
255
247
256
### Building your own custom field
257
+
248
258
To build your own field within a `FormBuilder`, we use `FormBuilderCustomField` which will require that you define your own `FormField`.
249
259
The `FormField` will not require a `validator` if the `validators` property is already defined in the `FormBuilderCustomField`.
260
+
250
261
```dart
251
262
var options = ["Option 1", "Option 2", "Option 3"];
252
263
```
@@ -285,30 +296,34 @@ FormBuilderCustomField(
285
296
```
286
297
287
298
## Validation
299
+
288
300
The `validators` attribute in fields take in any number of `FormFieldValidator` allowing composability
289
301
of validation functions as well as allow reusability of already defined validator methods.
290
302
291
303
### Built-in Validators
304
+
292
305
The package comes with several most common `FormFieldValidator`s such as required, numeric, mail, URL, min,
293
306
max, minLength, maxLength, IP, credit card etc. with default `errorText` in English but with
294
307
ability to include you own error message that will display whenever validation fails.
295
308
296
309
Available built-in validators include:
297
-
*`FormBuilderValidators.required()` - requires the field have a non-empty value.
298
-
*`FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
299
-
*`FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
300
-
*`FormBuilderValidators.max()` - requires the field's value to be less than or equal to the provided number.
301
-
*`FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
302
-
*`FormBuilderValidators.maxLength()` - requires the length of the field's value to be less than or equal to the provided maximum length.
303
-
*`FormBuilderValidators.pattern()` - requires the field's value to match the provided regex pattern.
304
-
*`FormBuilderValidators.email()` - requires the field's value to be a valid email address.
305
-
*``FormBuilderValidators.url()`` - requires the field's value to be a valid url.
306
-
*`FormBuilderValidators.IP()` - requires the field's value to be a valid IP address.
307
-
*`FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
308
-
*`FormBuilderValidators.date()` - requires the field's value to be a valid date string.
309
-
*`FormBuilderValidators.requiredTrue()` - requires the field's value be true.
310
+
311
+
-`FormBuilderValidators.required()` - requires the field have a non-empty value.
312
+
-`FormBuilderValidators.numeric()` - requires the field's value to be a valid number.
313
+
-`FormBuilderValidators.min()` - requires the field's value to be greater than or equal to the provided number.
314
+
-`FormBuilderValidators.max()` - requires the field's value to be less than or equal to the provided number.
315
+
-`FormBuilderValidators.minLength()` - requires the length of the field's value to be greater than or equal to the provided minimum length.
316
+
-`FormBuilderValidators.maxLength()` - requires the length of the field's value to be less than or equal to the provided maximum length.
317
+
-`FormBuilderValidators.pattern()` - requires the field's value to match the provided regex pattern.
318
+
-`FormBuilderValidators.email()` - requires the field's value to be a valid email address.
319
+
-`FormBuilderValidators.url()` - requires the field's value to be a valid url.
320
+
-`FormBuilderValidators.IP()` - requires the field's value to be a valid IP address.
321
+
-`FormBuilderValidators.creditCard()` - requires the field's value to be a valid credit card number.
322
+
-`FormBuilderValidators.date()` - requires the field's value to be a valid date string.
323
+
-`FormBuilderValidators.requiredTrue()` - requires the field's value be true.
310
324
311
325
Validation example:
326
+
312
327
```dart
313
328
FormBuilderTextField(
314
329
attribute: "age",
@@ -321,7 +336,9 @@ FormBuilderTextField(
321
336
```
322
337
323
338
### Custom validator function
339
+
324
340
As well as the built-in validators any function of type `FormFieldValidator` will be accepted into the list of `validators`.
341
+
325
342
```dart
326
343
FormBuilderTextField(
327
344
attribute: "over_18",
@@ -337,7 +354,9 @@ FormBuilderTextField(
337
354
```
338
355
339
356
### Conditional validation
357
+
340
358
You can also validate a field based on the value of another field
359
+
341
360
```
342
361
FormBuilderRadio(
343
362
decoration: InputDecoration(labelText: 'My best language'),
Made with [contributors-img](https://contributors-img.firebaseapp.com).
376
397
377
398
### Dependencies
399
+
378
400
This package is dependent on the following packages and plugins:
379
-
*[flutter_typeahead](https://pub.dev/packages/flutter_typeahead) by [AbdulRahmanAlHamali](https://github.com/AbdulRahmanAlHamali)
380
-
*[rating_bar](https://pub.dev/packages/rating_bar) by [Joshua Matta](https://github.com/joshmatta)
381
-
*[datetime_picker_formfield](https://pub.dev/packages/datetime_picker_formfield) by [Jacob Phillips](https://github.com/jifalops)
382
-
*[date_range_picker](https://github.com/anicdh/date_range_picker) by [anicdh](https://github.com/anicdh)
383
-
*[validators](https://pub.dev/packages/validators) by [dart-league](https://github.com/dart-league)
384
-
*[signature](https://pub.dev/packages/signature) by [4Q s.r.o.](https://github.com/4Q-s-r-o) with some minor improvements to fit our usage
385
-
*[flutter_colorpicker](https://pub.dev/packages/flutter_colorpicker) by [mchome](https://github.com/mchome)
386
-
*[flutter_chips_input](https://pub.dev/packages/flutter_chips_input) & [flutter_touch_spin](https://pub.dev/packages/flutter_touch_spin) by [Yours truly :-)](https://github.com/danvick)
401
+
402
+
-[flutter_typeahead](https://pub.dev/packages/flutter_typeahead) by [AbdulRahmanAlHamali](https://github.com/AbdulRahmanAlHamali)
403
+
-[rating_bar](https://pub.dev/packages/rating_bar) by [Joshua Matta](https://github.com/joshmatta)
404
+
-[datetime_picker_formfield](https://pub.dev/packages/datetime_picker_formfield) by [Jacob Phillips](https://github.com/jifalops)
405
+
-[date_range_picker](https://github.com/anicdh/date_range_picker) by [anicdh](https://github.com/anicdh)
406
+
-[validators](https://pub.dev/packages/validators) by [dart-league](https://github.com/dart-league)
407
+
-[signature](https://pub.dev/packages/signature) by [4Q s.r.o.](https://github.com/4Q-s-r-o) with some minor improvements to fit our usage
408
+
-[flutter_colorpicker](https://pub.dev/packages/flutter_colorpicker) by [mchome](https://github.com/mchome)
409
+
-[flutter_chips_input](https://pub.dev/packages/flutter_chips_input) & [flutter_touch_spin](https://pub.dev/packages/flutter_touch_spin) by [Yours truly :-)](https://github.com/danvick)
387
410
388
411
### RELATED PACKAGES
412
+
389
413
Here are other field types for `flutter_form_builder`:
414
+
390
415
-[form_builder_file_picker](https://pub.dev/packages/form_builder_file_picker) - A file picker field for `FlutterFormBuilder`.
391
416
-[form_builder_map_field](https://pub.dev/packages/form_builder_map_field) - A map input field for `FlutterFormBuilder`.
392
417
393
418
## FUTURE PLANS:
419
+
394
420
### Improvements
395
-
-[X] Allow addition of custom input types
396
-
-[X] Improve documentation by showing complete list of input types and their usage and options
397
-
-[X] Create a `transformer` function option that will convert field value when field is saved - can be used to convert string to number, change to uppercase etc.
398
-
-[X] Assert no duplicates in `FormBuilderInput`s `attribute` names
399
-
-[X] Allow options for Checkboxes and Radios to appear left or right - Done via `leadingInput` courtesy of [Sven Schöne](https://github.com/SvenSchoene)
400
-
-[X] Use flutter_touch_spin for FormBuilderStepper. Possibly rename to FormBuilderTouchSpin in next major version
401
-
-[X] For RangeSlider use Flutter provided
421
+
422
+
-[x] Allow addition of custom input types
423
+
-[x] Improve documentation by showing complete list of input types and their usage and options
424
+
-[x] Create a `transformer` function option that will convert field value when field is saved - can be used to convert string to number, change to uppercase etc.
425
+
-[x] Assert no duplicates in `FormBuilderInput`s `attribute` names
426
+
-[x] Allow options for Checkboxes and Radios to appear left or right - Done via `leadingInput` courtesy of [Sven Schöne](https://github.com/SvenSchoene)
427
+
-[x] Use flutter_touch_spin for FormBuilderStepper. Possibly rename to FormBuilderTouchSpin in next major version
428
+
-[x] For RangeSlider use Flutter provided
402
429
403
430
### Known Issues
404
-
* Setting `autovalidate` to `true` validates fields immediately they're rendered even if pristine - which is the default behavior in Flutter
405
-
* Form's `reset()` doesn't clear SignaturePad - You'll be forced to clear manually
431
+
432
+
- Setting `autovalidate` to `true` validates fields immediately they're rendered even if pristine - which is the default behavior in Flutter
433
+
- Form's `reset()` doesn't clear SignaturePad - You'll be forced to clear manually
406
434
407
435
## SUPPORT
436
+
408
437
If this package was helpful to you in delivering on your project or you just wanna to support this project, a cup of coffee would be highly appreciated ;-)
409
438
410
439
[](https://buymeacoff.ee/wb5M9y2Sz)
0 commit comments