Skip to content

Commit 66c02c3

Browse files
committed
Removed readOnly property from FormBuilderField and subclasses (unless applicable to particular subclass, like TextField).
1 parent 9fdc973 commit 66c02c3

29 files changed

+184
-207
lines changed

example/lib/sources/complete_form.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,22 +34,20 @@ class CompleteFormState extends State<CompleteForm> {
3434
children: <Widget>[
3535
FormBuilder(
3636
key: _formKey,
37-
skipReadOnly: true,
3837
autovalidateMode: AutovalidateMode.disabled,
3938
initialValue: {
4039
'movie_rating': 5,
4140
'best_language': 'Dart',
4241
'age': '13',
4342
'gender': 'Male'
4443
},
45-
readOnly: false,
4644
child: Column(
4745
children: <Widget>[
4846
FormBuilderSearchableDropdown(
4947
name: 'searchable_dropdown',
5048
items: allCountries,
5149
onChanged: _onChanged,
52-
readOnly: true,
50+
saveValue: false,
5351
),
5452
FormBuilderLocationField(
5553
name: 'location',
@@ -59,7 +57,7 @@ class CompleteFormState extends State<CompleteForm> {
5957
const SizedBox(height: 15),
6058
FormBuilderFilterChip(
6159
name: 'filter_chip',
62-
readOnly: true,
60+
saveValue: false,
6361
decoration: const InputDecoration(
6462
labelText: 'Select many options',
6563
),

lib/src/fields/form_builder_checkbox.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
7070
@required String name,
7171
FormFieldValidator<bool> validator,
7272
bool initialValue,
73-
bool readOnly = false,
73+
bool saveValue = true,
7474
InputDecoration decoration = const InputDecoration(),
7575
ValueChanged<bool> onChanged,
7676
ValueTransformer<bool> valueTransformer,
@@ -96,7 +96,7 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
9696
validator: validator,
9797
valueTransformer: valueTransformer,
9898
onChanged: onChanged,
99-
readOnly: readOnly,
99+
saveValue: saveValue,
100100
autovalidateMode: autovalidateMode,
101101
onSaved: onSaved,
102102
enabled: enabled,
@@ -114,12 +114,12 @@ class FormBuilderCheckbox extends FormBuilderField<bool> {
114114
title: title,
115115
subtitle: subtitle,
116116
value: state.value,
117-
onChanged: state.readOnly
118-
? null
119-
: (val) {
117+
onChanged: enabled
118+
? (val) {
120119
state.requestFocus();
121120
state.didChange(val);
122-
},
121+
}
122+
: null,
123123
checkColor: checkColor,
124124
activeColor: activeColor,
125125
secondary: secondary,

lib/src/fields/form_builder_checkbox_group.dart

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
3030
@required String name,
3131
FormFieldValidator validator,
3232
List<T> initialValue,
33-
bool readOnly = false,
33+
bool saveValue = true,
3434
InputDecoration decoration = const InputDecoration(),
3535
ValueChanged<List<T>> onChanged,
3636
ValueTransformer<List<T>> valueTransformer,
@@ -65,7 +65,7 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
6565
validator: validator,
6666
valueTransformer: valueTransformer,
6767
onChanged: onChanged,
68-
readOnly: readOnly,
68+
saveValue: saveValue,
6969
autovalidateMode: autovalidateMode,
7070
onSaved: onSaved,
7171
enabled: enabled,
@@ -85,9 +85,8 @@ class FormBuilderCheckboxGroup<T> extends FormBuilderField<List<T>> {
8585
state.requestFocus();
8686
field.didChange(val);
8787
},
88-
disabled: state.readOnly
89-
? options.map((e) => e.value).toList()
90-
: disabled,
88+
disabled:
89+
enabled ? disabled : options.map((e) => e.value).toList(),
9190
activeColor: activeColor,
9291
focusColor: focusColor,
9392
checkColor: checkColor,

lib/src/fields/form_builder_chips_input.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ class FormBuilderChipsInput<T> extends FormBuilderField<List<T>> {
2929
@required String name,
3030
FormFieldValidator<List<T>> validator,
3131
List<T> initialValue = const [],
32-
bool readOnly = false,
32+
bool saveValue = true,
3333
InputDecoration decoration = const InputDecoration(),
3434
ValueChanged<List<T>> onChanged,
3535
ValueTransformer<List<T>> valueTransformer,
@@ -61,7 +61,7 @@ class FormBuilderChipsInput<T> extends FormBuilderField<List<T>> {
6161
validator: validator,
6262
valueTransformer: valueTransformer,
6363
onChanged: onChanged,
64-
readOnly: readOnly,
64+
saveValue: saveValue,
6565
autovalidateMode: autovalidateMode,
6666
onSaved: onSaved,
6767
enabled: enabled,

lib/src/fields/form_builder_choice_chips.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
244244
@required String name,
245245
FormFieldValidator<T> validator,
246246
T initialValue,
247-
bool readOnly = false,
247+
bool saveValue = true,
248248
InputDecoration decoration = const InputDecoration(),
249249
ValueChanged<T> onChanged,
250250
ValueTransformer<T> valueTransformer,
@@ -282,7 +282,7 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
282282
validator: validator,
283283
valueTransformer: valueTransformer,
284284
onChanged: onChanged,
285-
readOnly: readOnly,
285+
saveValue: saveValue,
286286
autovalidateMode: autovalidateMode,
287287
onSaved: onSaved,
288288
enabled: enabled,
@@ -308,13 +308,13 @@ class FormBuilderChoiceChip<T> extends FormBuilderField<T> {
308308
ChoiceChip(
309309
label: option,
310310
selected: field.value == option.value,
311-
onSelected: state.readOnly
312-
? null
313-
: (selected) {
311+
onSelected: enabled
312+
? (selected) {
314313
final choice = selected ? option.value : null;
315314
state.requestFocus();
316315
state.didChange(choice);
317-
},
316+
}
317+
: null,
318318
selectedColor: selectedColor,
319319
disabledColor: disabledColor,
320320
backgroundColor: backgroundColor,

lib/src/fields/form_builder_color_picker.dart

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
7777
ValueTransformer<Color> valueTransformer,
7878
ValueChanged<Color> onChanged,
7979
FormFieldSetter<Color> onSaved,
80+
bool saveValue = true,
8081
VoidCallback onReset,
8182
this.controller,
8283
InputDecoration decoration = const InputDecoration(),
@@ -117,7 +118,7 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
117118
validator: validator,
118119
valueTransformer: valueTransformer,
119120
onChanged: onChanged,
120-
readOnly: readOnly,
121+
saveValue: saveValue,
121122
autovalidateMode: autovalidateMode,
122123
onSaved: onSaved,
123124
enabled: enabled,
@@ -147,7 +148,7 @@ class FormBuilderColorPickerField extends FormBuilderField<Color> {
147148
),
148149
),
149150
enabled: enabled,
150-
readOnly: state.readOnly,
151+
readOnly: readOnly,
151152
controller: state._effectiveController,
152153
focusNode: state.effectiveFocusNode,
153154
textAlign: textAlign,
@@ -210,7 +211,7 @@ class _FormBuilderColorPickerFieldState
210211
}
211212

212213
Future<void> _handleFocus() async {
213-
if (effectiveFocusNode.hasFocus && !readOnly) {
214+
if (effectiveFocusNode.hasFocus && widget.enabled) {
214215
await Future.microtask(
215216
() => FocusScope.of(context).requestFocus(FocusNode()));
216217
final selected = await showDialog<bool>(

lib/src/fields/form_builder_date_range_picker.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ class FormBuilderDateRangePicker extends FormBuilderField<List<DateTime>> {
5353
@required String name,
5454
FormFieldValidator<List<DateTime>> validator,
5555
List<DateTime> initialValue,
56-
bool readOnly = false,
56+
bool saveValue = true,
5757
InputDecoration decoration = const InputDecoration(),
5858
ValueChanged<List<DateTime>> onChanged,
5959
ValueTransformer<List<DateTime>> valueTransformer,
@@ -122,7 +122,7 @@ class FormBuilderDateRangePicker extends FormBuilderField<List<DateTime>> {
122122
validator: validator,
123123
valueTransformer: valueTransformer,
124124
onChanged: onChanged,
125-
readOnly: readOnly,
125+
saveValue: saveValue,
126126
autovalidateMode: autovalidateMode,
127127
onSaved: onSaved,
128128
enabled: enabled,
@@ -133,11 +133,11 @@ class FormBuilderDateRangePicker extends FormBuilderField<List<DateTime>> {
133133
final FormBuilderDateRangePickerState state = field;
134134

135135
return TextField(
136-
enabled: !state.readOnly,
136+
enabled: enabled,
137137
style: style,
138-
focusNode: state.readOnly
139-
? AlwaysDisabledFocusNode()
140-
: state.effectiveFocusNode,
138+
focusNode: enabled
139+
? state.effectiveFocusNode
140+
: AlwaysDisabledFocusNode(),
141141
decoration: state.decoration(),
142142
// initialValue: "${_initialValue ?? ''}",
143143
maxLines: maxLines,

lib/src/fields/form_builder_date_time_picker.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class FormBuilderDateTimePicker extends FormBuilderField<DateTime> {
151151
@required String name,
152152
FormFieldValidator<DateTime> validator,
153153
DateTime initialValue,
154-
bool readOnly = false,
154+
bool saveValue = true,
155155
InputDecoration decoration = const InputDecoration(),
156156
ValueChanged<DateTime> onChanged,
157157
ValueTransformer<DateTime> valueTransformer,
@@ -226,7 +226,7 @@ class FormBuilderDateTimePicker extends FormBuilderField<DateTime> {
226226
validator: validator,
227227
valueTransformer: valueTransformer,
228228
onChanged: onChanged,
229-
readOnly: readOnly,
229+
saveValue: saveValue,
230230
autovalidateMode: autovalidateMode,
231231
onSaved: onSaved,
232232
enabled: enabled,
@@ -250,7 +250,7 @@ class FormBuilderDateTimePicker extends FormBuilderField<DateTime> {
250250
autofocus: autofocus,
251251
decoration: state.decoration(),
252252
readOnly: true,
253-
enabled: state.readOnly ? false : enabled,
253+
enabled: enabled,
254254
autocorrect: autocorrect,
255255
controller: state._textFieldController,
256256
focusNode: state.effectiveFocusNode,

lib/src/fields/form_builder_dropdown.dart

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -185,7 +185,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
185185
@required String name,
186186
FormFieldValidator<T> validator,
187187
T initialValue,
188-
bool readOnly = false,
188+
bool saveValue = true,
189189
InputDecoration decoration = const InputDecoration(),
190190
ValueChanged<T> onChanged,
191191
ValueTransformer<T> valueTransformer,
@@ -220,7 +220,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
220220
validator: validator,
221221
valueTransformer: valueTransformer,
222222
onChanged: onChanged,
223-
readOnly: readOnly,
223+
saveValue: saveValue,
224224
autovalidateMode: autovalidateMode,
225225
onSaved: onSaved,
226226
enabled: enabled,
@@ -262,9 +262,9 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
262262
icon: icon,
263263
iconDisabledColor: iconDisabledColor,
264264
iconEnabledColor: iconEnabledColor,
265-
onChanged: (state.readOnly || !enabled)
266-
? null
267-
: (value) => _changeValue<T>(field, value),
265+
onChanged: enabled
266+
? (value) => _changeValue<T>(field, value)
267+
: null,
268268
onTap: onTap,
269269
focusNode: state.effectiveFocusNode,
270270
autofocus: autofocus,
@@ -275,7 +275,7 @@ class FormBuilderDropdown<T> extends FormBuilderField<T> {
275275
),
276276
),
277277
),
278-
if (allowClear && !readOnly && field.value != null) ...[
278+
if (allowClear && enabled && field.value != null) ...[
279279
const VerticalDivider(),
280280
InkWell(
281281
child: clearIcon,

lib/src/fields/form_builder_file_picker.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
4747
@required String name,
4848
FormFieldValidator<List<PlatformFile>> validator,
4949
List<PlatformFile> initialValue,
50-
bool readOnly = false,
50+
bool saveValue = true,
5151
InputDecoration decoration = const InputDecoration(),
5252
ValueChanged<List<PlatformFile>> onChanged,
5353
ValueTransformer<List<PlatformFile>> valueTransformer,
@@ -72,7 +72,7 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
7272
validator: validator,
7373
valueTransformer: valueTransformer,
7474
onChanged: onChanged,
75-
readOnly: readOnly,
75+
saveValue: saveValue,
7676
autovalidateMode: autovalidateMode,
7777
onSaved: onSaved,
7878
enabled: enabled,
@@ -93,11 +93,11 @@ class FormBuilderFilePicker extends FormBuilderField<List<PlatformFile>> {
9393
Text('${state._files.length} / $maxFiles'),
9494
InkWell(
9595
child: selector,
96-
onTap: (state.readOnly ||
97-
(state._remainingItemCount != null &&
98-
state._remainingItemCount <= 0))
99-
? null
100-
: () => state.pickFiles(field),
96+
onTap: enabled &&
97+
(null == state._remainingItemCount ||
98+
state._remainingItemCount > 0)
99+
? () => state.pickFiles(field)
100+
: null,
101101
),
102102
],
103103
),
@@ -219,7 +219,7 @@ class _FormBuilderFilePickerState
219219
width: double.infinity,
220220
color: Colors.white.withOpacity(.8),
221221
),
222-
if (!readOnly)
222+
if (widget.enabled)
223223
Positioned(
224224
top: 0,
225225
right: 0,

0 commit comments

Comments
 (0)