Skip to content

Commit 39a28cf

Browse files
committed
feat(core): got rid of form_builder_fields package, merged with form_builder
1 parent ee7509a commit 39a28cf

File tree

120 files changed

+463
-2402
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

120 files changed

+463
-2402
lines changed

.github/workflows/form_builder_fields.yaml

Lines changed: 0 additions & 62 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,36 +20,27 @@ Flutter Form Builder provides an easy way of working with forms in Flutter by re
2020

2121
- [FormBuilder Core (`flutter_form_builder`)](#flutter_form_builder)
2222
- [FormBuilder Extra Fields (`form_builder_extra_fields`)](#form_builder_extra_fields)
23-
- [FormBuilder Fields (`form_builder_fields`)](#form_builder_fields)
2423
- [FormBuilder Validators (`form_builder_validators`)](#form_builder_validators)
2524

2625
### flutter_form_builder
2726
> [![Pub Version](https://img.shields.io/pub/v/flutter_form_builder?logo=flutter&style=for-the-badge)](https://pub.dev/packages/flutter_form_builder)
2827
2928
FormBuilder helps in creation of data collection forms in Flutter by removing the boilerplate needed to build a form, validate fields, react to changes,
3029
and collect final user input.
31-
This package provides APIs to manage your Form and generating a FormBuilder compliant FormField. It is required by `form_builder_fields` and `form_builder_extra_fields` packages.
30+
It provides APIs to manage your Form and generating a FormBuilder compliant FormField. It is required by `form_builder_extra_fields` packages.
31+
This package also contains common ready-made form input fields. The package gives you a convenient way of adding fields instead of creating your own FormBuilderField from scratch.
3232

3333
[[View Documentation][core_docs]] [[View Source][core_code]]
3434

3535
### form_builder_extra_fields
3636
> [![Pub Version](https://img.shields.io/pub/v/form_builder_extra_fields?logo=flutter&style=for-the-badge)](https://pub.dev/packages/form_builder_extra_fields)
3737
38-
Form Builder Fields provides ready-made form input fields. Just like the form_builder_fields package, it gives you a convenient way of adding fields instead of creating your own FormBuilderField from scratch.
38+
Form Builder Fields provides ready-made form input fields. Just like the flutter_form_builder package, it gives you a convenient way of adding fields instead of creating your own FormBuilderField from scratch.
3939

40-
Unlike form_builder_fields package which depends purely on Flutter provided input fields, flutter_extra_fields depends on external libraries to provide input widgets and extends them to be FormBuilderFields.
40+
Unlike flutter_form_builder package which depends purely on Flutter provided input fields, flutter_extra_fields depends on external libraries to provide input widgets and extends them to be FormBuilderFields.
4141

4242
[[View Documentation][extra_fields_docs]] [[View Source][extra_fields_code]]
4343

44-
45-
### form_builder_fields
46-
> [![Pub Version](https://img.shields.io/pub/v/form_builder_fields?logo=flutter&style=for-the-badge)](https://pub.dev/packages/form_builder_fields)
47-
48-
Form Builder Fields provides common ready-made form input fields. The package gives you a convenient way of adding fields instead of creating your own FormBuilderField from scratch.
49-
50-
[[View Documentation][fields_docs]] [[View Source][fields_code]]
51-
52-
5344
### form_builder_validators
5445
> [![Pub Version](https://img.shields.io/pub/v/form_builder_validators?logo=flutter&style=for-the-badge)](https://pub.dev/packages/form_builder_validators)
5546
@@ -90,10 +81,6 @@ Made with [contributors-img](https://contributors-img.firebaseapp.com).
9081

9182
[extra_fields_docs]: https://github.com/danvick/flutter_form_builder/blob/split_packages/packages/form_builder_extra_fields/README.md
9283

93-
[fields_code]: https://github.com/danvick/flutter_form_builder/tree/split_packages/packages/form_builder_fields
94-
95-
[fields_docs]: https://github.com/danvick/flutter_form_builder/blob/split_packages/packages/form_builder_fields/README.md
96-
9784
[validators_code]: https://github.com/danvick/flutter_form_builder/tree/split_packages/packages/form_builder_validators
9885

9986
[validators_docs]: https://github.com/danvick/flutter_form_builder/blob/split_packages/packages/form_builder_validators/README.md

packages/flutter_form_builder/CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
## [7.0.0-beta.0] - 02-Sep-2021
2+
* Merged back `form_builder_fields` into `flutter_form_builder`
3+
14
## [7.0.0-alpha.3] - 01-Sep-2021
25
* When form validation fails, automatically scroll to first error
36
* New way to programmatically induce custom errors by calling `GlobalKey<FormBuilderState>.invalidateField()` or `GlobalKey<FormBuilderFieldState>.invalidate()`

packages/flutter_form_builder/README.md

Lines changed: 194 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
This package helps in creation of data collection forms in Flutter by removing the boilerplate needed to build a form, validate fields, react to changes,
44
and collect final user input.
5+
6+
Also included are common ready-made form input fields for FormBuilder. This gives you a convenient way of adding common ready-made input fields instead of creating your own FormBuilderField from scratch.
57
___
68

79
[![Pub Version](https://img.shields.io/pub/v/flutter_form_builder?logo=flutter&style=for-the-badge)](https://pub.dev/packages/flutter_form_builder)
@@ -17,8 +19,14 @@ ___
1719

1820
### Example
1921
```dart
22+
import 'package:flutter_form_builder/flutter_form_builder.dart';
23+
24+
...
25+
2026
final _formKey = GlobalKey<FormBuilderState>();
2127
28+
...
29+
2230
@override
2331
Widget build(BuildContext context) {
2432
return Column(
@@ -28,7 +36,138 @@ Widget build(BuildContext context) {
2836
autovalidate: true,
2937
child: Column(
3038
children: <Widget>[
31-
39+
FormBuilderFilterChip(
40+
name: 'filter_chip',
41+
decoration: InputDecoration(
42+
labelText: 'Select many options',
43+
),
44+
options: [
45+
FormBuilderFieldOption(
46+
value: 'Test', child: Text('Test')),
47+
FormBuilderFieldOption(
48+
value: 'Test 1', child: Text('Test 1')),
49+
FormBuilderFieldOption(
50+
value: 'Test 2', child: Text('Test 2')),
51+
FormBuilderFieldOption(
52+
value: 'Test 3', child: Text('Test 3')),
53+
FormBuilderFieldOption(
54+
value: 'Test 4', child: Text('Test 4')),
55+
],
56+
),
57+
FormBuilderChoiceChip(
58+
name: 'choice_chip',
59+
decoration: InputDecoration(
60+
labelText: 'Select an option',
61+
),
62+
options: [
63+
FormBuilderFieldOption(
64+
value: 'Test', child: Text('Test')),
65+
FormBuilderFieldOption(
66+
value: 'Test 1', child: Text('Test 1')),
67+
FormBuilderFieldOption(
68+
value: 'Test 2', child: Text('Test 2')),
69+
FormBuilderFieldOption(
70+
value: 'Test 3', child: Text('Test 3')),
71+
FormBuilderFieldOption(
72+
value: 'Test 4', child: Text('Test 4')),
73+
],
74+
),
75+
FormBuilderDateTimePicker(
76+
name: 'date',
77+
// onChanged: _onChanged,
78+
inputType: InputType.time,
79+
decoration: InputDecoration(
80+
labelText: 'Appointment Time',
81+
),
82+
initialTime: TimeOfDay(hour: 8, minute: 0),
83+
// initialValue: DateTime.now(),
84+
// enabled: true,
85+
),
86+
FormBuilderDateRangePicker(
87+
name: 'date_range',
88+
firstDate: DateTime(1970),
89+
lastDate: DateTime(2030),
90+
format: DateFormat('yyyy-MM-dd'),
91+
onChanged: _onChanged,
92+
decoration: InputDecoration(
93+
labelText: 'Date Range',
94+
helperText: 'Helper text',
95+
hintText: 'Hint text',
96+
),
97+
),
98+
FormBuilderSlider(
99+
name: 'slider',
100+
validator: FormBuilderValidators.compose([
101+
FormBuilderValidators.min(context, 6),
102+
]),
103+
onChanged: _onChanged,
104+
min: 0.0,
105+
max: 10.0,
106+
initialValue: 7.0,
107+
divisions: 20,
108+
activeColor: Colors.red,
109+
inactiveColor: Colors.pink[100],
110+
decoration: InputDecoration(
111+
labelText: 'Number of things',
112+
),
113+
),
114+
FormBuilderCheckbox(
115+
name: 'accept_terms',
116+
initialValue: false,
117+
onChanged: _onChanged,
118+
title: RichText(
119+
text: TextSpan(
120+
children: [
121+
TextSpan(
122+
text: 'I have read and agree to the ',
123+
style: TextStyle(color: Colors.black),
124+
),
125+
TextSpan(
126+
text: 'Terms and Conditions',
127+
style: TextStyle(color: Colors.blue),
128+
),
129+
],
130+
),
131+
),
132+
validator: FormBuilderValidators.equal(
133+
context,
134+
true,
135+
errorText:
136+
'You must accept terms and conditions to continue',
137+
),
138+
),
139+
FormBuilderTextField(
140+
name: 'age',
141+
decoration: InputDecoration(
142+
labelText:
143+
'This value is passed along to the [Text.maxLines] attribute of the [Text] widget used to display the hint text.',
144+
),
145+
onChanged: _onChanged,
146+
// valueTransformer: (text) => num.tryParse(text),
147+
validator: FormBuilderValidators.compose([
148+
FormBuilderValidators.required(context),
149+
FormBuilderValidators.numeric(context),
150+
FormBuilderValidators.max(context, 70),
151+
]),
152+
keyboardType: TextInputType.number,
153+
),
154+
FormBuilderDropdown(
155+
name: 'gender',
156+
decoration: InputDecoration(
157+
labelText: 'Gender',
158+
),
159+
// initialValue: 'Male',
160+
allowClear: true,
161+
hint: Text('Select Gender'),
162+
validator: FormBuilderValidators.compose(
163+
[FormBuilderValidators.required(context)]),
164+
items: genderOptions
165+
.map((gender) => DropdownMenuItem(
166+
value: gender,
167+
child: Text('$gender'),
168+
))
169+
.toList(),
170+
),
32171
],
33172
),
34173
),
@@ -65,13 +204,27 @@ Widget build(BuildContext context) {
65204
),
66205
),
67206
],
68-
),
207+
)
69208
],
70209
);
71210
}
72211
```
73212

74-
## FormBuilderField attributes
213+
## Input widgets
214+
The currently supported fields include:
215+
* `FormBuilderCheckbox` - Single Checkbox field
216+
* `FormBuilderCheckboxGroup` - List of Checkboxes for multiple selection
217+
* `FormBuilderChoiceChip` - Creates a chip that acts like a radio button.
218+
* `FormBuilderDateRangePicker` - For selection of a range of dates
219+
* `FormBuilderDateTimePicker` - For `Date`, `Time` and `DateTime` input
220+
* `FormBuilderDropdown` - Used to select one value from a list as a Dropdown
221+
* `FormBuilderFilterChip` - Creates a chip that acts like a checkbox.
222+
* `FormBuilderRadioGroup` - Used to select one value from a list of Radio Widgets
223+
* `FormBuilderRangeSlider` - Used to select a range from a range of values
224+
* `FormBuilderSegmentedControl` - For selection of a value using the `CupertinoSegmentedControl` widget as an input
225+
* `FormBuilderSlider` - For selection of a numerical value on a slider
226+
* `FormBuilderSwitch` - On/Off switch field
227+
* `FormBuilderTextField` - A Material Design text field input.
75228

76229
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:
77230

@@ -142,6 +295,42 @@ _formKey.currentState.patchValue({
142295
```
143296

144297
### Programmatically inducing an error
298+
#### Option 1 - Using FormBuilder / FieldBuilderField key
299+
```dart
300+
final _formKey = GlobalKey<FormBuilderState>();
301+
final _emailFieldKey = GlobalKey<FormBuilderFieldState>();
302+
...
303+
FormBuilder(
304+
key: _formKey,
305+
child: Column(
306+
children: [
307+
FormBuilderTextField(
308+
key: _emailFieldKey
309+
name: 'email',
310+
decoration: InputDecoration(labelText: 'Email'),
311+
validator: FormBuilderValidators.compose([
312+
FormBuilderValidators.required(context),
313+
FormBuilderValidators.email(context),
314+
]),
315+
),
316+
RaisedButton(
317+
child: Text('Submit'),
318+
onPressed: () async {
319+
if(await checkIfEmailExists()){
320+
// Either invalidate using Form Key
321+
_formKey.currentState?.invalidateField(name: 'email', errorText: 'Email already taken.');
322+
// OR invalidate using Field Key
323+
_emailFieldKey.currentState?.invalidate('Email already taken.');
324+
}
325+
},
326+
),
327+
],
328+
),
329+
),
330+
331+
```
332+
333+
#### Option 2 - Using InputDecoration.errorText
145334
Declare a variable to hold your error:
146335
```dart
147336
String _emailError;
@@ -168,7 +357,7 @@ RaisedButton(
168357
child: Text('Submit'),
169358
onPressed: () async {
170359
setState(() => _emailError = null);
171-
if(checkIfEmailExists()){
360+
if(await checkIfEmailExists()){
172361
setState(() => _emailError = 'Email already taken.');
173362
}
174363
},
@@ -207,9 +396,9 @@ FormBuilderRadioGroup(
207396
},
208397
),
209398
```
399+
210400
### Ecosystem
211401
Here are additional packages that you can use to extend `flutter_form_builder`'s functionality.
212-
* [form_builder_fields](https://pub.dev/packages/form_builder_fields) - provides common ready-made form input fields compartible with `flutter_form_builder`.
213402
* [form_builder_validators](https://pub.dev/packages/form_builder_validators) - provides a convenient way of validating data entered into any Flutter `FormField`.
214403
* [form_builder_extra_fields](https://pub.dev/packages/form_builder_extra_fields) - provides additional ready-made form input fields compartible with `flutter_form_builder`.
215404
* [form_builder_file_picker](https://pub.dev/packages/form_builder_file_picker) - A `FormbuilderField` that allows selecting image(s) from user device storage.

packages/flutter_form_builder/example/android/app/src/main/AndroidManifest.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
22
package="dev.danvickmiller.flutterformbuilder.example">
33
<application
4-
android:label="example"
4+
android:label="FormBuilder Example"
55
android:icon="@mipmap/ic_launcher">
66
<activity
77
android:name=".MainActivity"

packages/flutter_form_builder/example/ios/Runner/Info.plist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<key>CFBundleInfoDictionaryVersion</key>
1212
<string>6.0</string>
1313
<key>CFBundleName</key>
14-
<string>example</string>
14+
<string>Form Builder</string>
1515
<key>CFBundlePackageType</key>
1616
<string>APPL</string>
1717
<key>CFBundleShortVersionString</key>
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)