Merge pull request #11 from Iconica-Development/fix/switch_onchange

fix: onchange of switch not firing
This commit is contained in:
Gorter-dev 2022-10-27 16:04:57 +02:00 committed by GitHub
commit 86426c09bc
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 11 additions and 0 deletions

View file

@ -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

View file

@ -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,
);

View file

@ -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(() {