Skip to content

Commit cbd3061

Browse files
committed
Added onChanged to all predefined fields except SignaturePad
1 parent 2f2b848 commit cbd3061

12 files changed

+72
-12
lines changed

lib/src/inputs/form_builder_checkbox.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FormBuilderCheckbox extends StatefulWidget {
88
final bool initialValue;
99
final bool readonly;
1010
final InputDecoration decoration;
11+
final ValueChanged onChanged;
1112

1213
final Widget label;
1314

@@ -18,6 +19,7 @@ class FormBuilderCheckbox extends StatefulWidget {
1819
this.validators = const [],
1920
this.readonly = false,
2021
this.decoration = const InputDecoration(),
22+
this.onChanged,
2123
});
2224

2325
@override
@@ -66,13 +68,15 @@ class _FormBuilderCheckboxState extends State<FormBuilderCheckbox> {
6668
? null
6769
: (bool value) {
6870
field.didChange(value);
71+
if (widget.onChanged != null) widget.onChanged(value);
6972
},
7073
),
7174
onTap: _readonly
7275
? null
7376
: () {
7477
bool newValue = !(field.value ?? false);
7578
field.didChange(newValue);
79+
if (widget.onChanged != null) widget.onChanged(newValue);
7680
},
7781
),
7882
);

lib/src/inputs/form_builder_checkbox_list.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FormBuilderCheckboxList extends StatefulWidget {
88
final dynamic initialValue;
99
final bool readonly;
1010
final InputDecoration decoration;
11+
final ValueChanged onChanged;
1112

1213
final List<FormBuilderInputOption> options;
1314

@@ -18,6 +19,7 @@ class FormBuilderCheckboxList extends StatefulWidget {
1819
this.validators = const [],
1920
this.readonly = false,
2021
this.decoration = const InputDecoration(),
22+
this.onChanged,
2123
});
2224

2325
@override
@@ -69,6 +71,7 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
6971
else
7072
currValue.remove(widget.options[i].value);
7173
field.didChange(currValue);
74+
if (widget.onChanged != null) widget.onChanged(currValue);
7275
},
7376
),
7477
title: Text(
@@ -82,6 +85,8 @@ class _FormBuilderCheckboxListState extends State<FormBuilderCheckboxList> {
8285
else
8386
currentValue.remove(widget.options[i].value);
8487
field.didChange(currentValue);
88+
if (widget.onChanged != null)
89+
widget.onChanged(currentValue);
8590
},
8691
),
8792
Divider(

lib/src/inputs/form_builder_chips_input.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FormBuilderChipsInput<T> extends StatefulWidget {
99
final List<T> initialValue;
1010
final bool readonly;
1111
final InputDecoration decoration;
12+
final ValueChanged onChanged;
1213

1314
final ChipsInputSuggestions findSuggestions;
1415

@@ -28,7 +29,7 @@ class FormBuilderChipsInput<T> extends StatefulWidget {
2829
this.readonly = false,
2930
this.decoration = const InputDecoration(),
3031
this.onChipTapped,
31-
this.maxChips,
32+
this.maxChips, this.onChanged,
3233
});
3334

3435
@override
@@ -73,6 +74,7 @@ class _FormBuilderChipsInputState extends State<FormBuilderChipsInput> {
7374
findSuggestions: widget.findSuggestions,
7475
onChanged: (data) {
7576
field.didChange(data);
77+
if (widget.onChanged != null) widget.onChanged(data);
7678
},
7779
maxChips: widget.maxChips,
7880
chipBuilder: widget.chipBuilder,

lib/src/inputs/form_builder_dropdown.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FormBuilderDropdown extends StatefulWidget {
88
final dynamic initialValue;
99
final bool readonly;
1010
final InputDecoration decoration;
11+
final ValueChanged onChanged;
1112

1213
final Widget hint;
1314
final List<DropdownMenuItem> items;
@@ -31,7 +32,7 @@ class FormBuilderDropdown extends StatefulWidget {
3132
this.hint,
3233
this.initialValue,
3334
this.style,
34-
this.disabledHint,
35+
this.disabledHint, this.onChanged,
3536
});
3637

3738
@override
@@ -82,6 +83,7 @@ class _FormBuilderDropdownState extends State<FormBuilderDropdown> {
8283
? null
8384
: (value) {
8485
field.didChange(value);
86+
if (widget.onChanged != null) widget.onChanged(value);
8587
},
8688
),
8789
);

lib/src/inputs/form_builder_radio.dart

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FormBuilderRadio extends StatefulWidget {
88
final dynamic initialValue;
99
final bool readonly;
1010
final InputDecoration decoration;
11+
final ValueChanged onChanged;
1112

1213
final List<FormBuilderInputOption> options;
1314

@@ -17,7 +18,7 @@ class FormBuilderRadio extends StatefulWidget {
1718
this.initialValue,
1819
this.validators = const [],
1920
this.readonly = false,
20-
this.decoration = const InputDecoration(),
21+
this.decoration = const InputDecoration(), this.onChanged,
2122
});
2223

2324
@override
@@ -67,12 +68,14 @@ class _FormBuilderRadioState extends State<FormBuilderRadio> {
6768
? null
6869
: (dynamic value) {
6970
field.didChange(value);
71+
if (widget.onChanged != null) widget.onChanged(value);
7072
},
7173
),
7274
onTap: _readonly
7375
? null
7476
: () {
7577
field.didChange(widget.options[i].value);
78+
if (widget.onChanged != null) widget.onChanged(widget.options[i].value);
7679
},
7780
),
7881
Divider(

lib/src/inputs/form_builder_rate.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FormBuilderRate extends StatefulWidget {
99
final num initialValue;
1010
final bool readonly;
1111
final InputDecoration decoration;
12+
final ValueChanged onChanged;
1213

1314
final num max;
1415
final IconData icon;
@@ -22,7 +23,7 @@ class FormBuilderRate extends StatefulWidget {
2223
this.decoration = const InputDecoration(),
2324
this.max,
2425
this.icon = Icons.star,
25-
this.iconSize = 24.0,
26+
this.iconSize = 24.0, this.onChanged,
2627
});
2728

2829
@override
@@ -70,6 +71,7 @@ class _FormBuilderRateState extends State<FormBuilderRate> {
7071
? null
7172
: (value) {
7273
field.didChange(value);
74+
if (widget.onChanged != null) widget.onChanged(value);
7375
},
7476
),
7577
);

lib/src/inputs/form_builder_segmented_control.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FormBuilderSegmentedControl extends StatefulWidget {
99
final dynamic initialValue;
1010
final bool readonly;
1111
final InputDecoration decoration;
12+
final ValueChanged onChanged;
1213

1314
final List<FormBuilderInputOption> options;
1415

@@ -19,6 +20,7 @@ class FormBuilderSegmentedControl extends StatefulWidget {
1920
this.validators = const [],
2021
this.readonly = false,
2122
this.decoration = const InputDecoration(),
23+
this.onChanged,
2224
});
2325

2426
@override
@@ -84,8 +86,10 @@ class _FormBuilderSegmentedControlState
8486
onValueChanged: (dynamic value) {
8587
if (_readonly) {
8688
field.reset();
87-
} else
89+
} else {
8890
field.didChange(value);
91+
if (widget.onChanged != null) widget.onChanged(value);
92+
}
8993
},
9094
),
9195
),

lib/src/inputs/form_builder_slider.dart

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FormBuilderSlider extends StatefulWidget {
88
final num initialValue;
99
final bool readonly;
1010
final InputDecoration decoration;
11+
final ValueChanged onChanged;
1112

1213
final num max;
1314
final num min;
@@ -21,7 +22,7 @@ class FormBuilderSlider extends StatefulWidget {
2122
this.validators = const [],
2223
this.readonly = false,
2324
this.decoration = const InputDecoration(),
24-
this.divisions,
25+
this.divisions, this.onChanged,
2526
});
2627

2728
@override
@@ -71,8 +72,9 @@ class _FormBuilderSliderState extends State<FormBuilderSlider> {
7172
divisions: widget.divisions,
7273
onChanged: _readonly
7374
? null
74-
: (double value) {
75+
: (num value) {
7576
field.didChange(value);
77+
if (widget.onChanged != null) widget.onChanged(value);
7678
},
7779
),
7880
Row(

lib/src/inputs/form_builder_stepper.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ class FormBuilderStepper extends StatefulWidget {
99
final num initialValue;
1010
final bool readonly;
1111
final InputDecoration decoration;
12+
final ValueChanged onChanged;
1213

1314
final num step;
1415
final num min;
@@ -24,7 +25,7 @@ class FormBuilderStepper extends StatefulWidget {
2425
this.step,
2526
this.min,
2627
this.max,
27-
this.size = 24.0,
28+
this.size = 24.0, this.onChanged,
2829
});
2930

3031
@override
@@ -72,6 +73,7 @@ class _FormBuilderStepperState extends State<FormBuilderStepper> {
7273
? null
7374
: (value) {
7475
field.didChange(value);
76+
if (widget.onChanged != null) widget.onChanged(value);
7577
},
7678
),
7779
);

lib/src/inputs/form_builder_switch.dart

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ class FormBuilderSwitch extends StatefulWidget {
88
final bool initialValue;
99
final bool readonly;
1010
final InputDecoration decoration;
11+
final ValueChanged onChanged;
1112

1213
final Widget label;
1314

@@ -18,6 +19,7 @@ class FormBuilderSwitch extends StatefulWidget {
1819
this.validators = const [],
1920
this.readonly = false,
2021
this.decoration = const InputDecoration(),
22+
this.onChanged,
2123
});
2224

2325
@override
@@ -66,13 +68,15 @@ class _FormBuilderSwitchState extends State<FormBuilderSwitch> {
6668
? null
6769
: (bool value) {
6870
field.didChange(value);
71+
if (widget.onChanged != null) widget.onChanged(value);
6972
},
7073
),
7174
onTap: _readonly
7275
? null
7376
: () {
7477
bool newValue = !(field.value ?? false);
7578
field.didChange(newValue);
79+
if (widget.onChanged != null) widget.onChanged(newValue);
7680
},
7781
),
7882
);

0 commit comments

Comments
 (0)