mirror of
https://github.com/Iconica-Development/flutter_form_wizard.git
synced 2025-05-19 10:53:49 +02:00
Merge pull request #11 from Iconica-Development/fix/switch_onchange
fix: onchange of switch not firing
This commit is contained in:
commit
86426c09bc
3 changed files with 11 additions and 0 deletions
|
@ -30,3 +30,7 @@
|
|||
- Added the id of the input field on the input check widget.
|
||||
- Ability to set the height of the carousel input field.
|
||||
- InputController now contains the onSubmit callback.
|
||||
|
||||
## 2.0.1 - October 27th 2022
|
||||
|
||||
- onChange of switch input not firing fixed
|
||||
|
|
|
@ -25,6 +25,7 @@ class FlutterFormInputSwitch extends FlutterFormInputWidget<bool> {
|
|||
onSaved: (value) {
|
||||
controller.onSaved(value);
|
||||
},
|
||||
onChanged: controller.onChanged,
|
||||
validator: (value) => controller.onValidate(value, _),
|
||||
initialValue: controller.value ?? false,
|
||||
);
|
||||
|
|
|
@ -7,6 +7,7 @@ class SwitchFormField extends FormField<bool> {
|
|||
required FormFieldValidator<bool> validator,
|
||||
bool initialValue = false,
|
||||
bool autovalidate = false,
|
||||
void Function(bool? value)? onChanged,
|
||||
}) : super(
|
||||
key: key,
|
||||
onSaved: onSaved,
|
||||
|
@ -16,6 +17,7 @@ class SwitchFormField extends FormField<bool> {
|
|||
return SwitchWidget(
|
||||
initialValue: initialValue,
|
||||
state: state,
|
||||
onChanged: onChanged,
|
||||
);
|
||||
});
|
||||
}
|
||||
|
@ -24,11 +26,13 @@ class SwitchWidget extends StatefulWidget {
|
|||
const SwitchWidget({
|
||||
this.initialValue = false,
|
||||
required this.state,
|
||||
this.onChanged,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final bool initialValue;
|
||||
final FormFieldState<bool> state;
|
||||
final void Function(bool? value)? onChanged;
|
||||
|
||||
@override
|
||||
State<SwitchWidget> createState() => _SwitchWidgetState();
|
||||
|
@ -42,6 +46,8 @@ class _SwitchWidgetState extends State<SwitchWidget> {
|
|||
return Switch(
|
||||
value: value,
|
||||
onChanged: (bool value) {
|
||||
widget.onChanged?.call(value);
|
||||
|
||||
widget.state.didChange(value);
|
||||
|
||||
setState(() {
|
||||
|
|
Loading…
Reference in a new issue