Merge pull request #6 from SimonIT/OnChanged_missing
Add onChanged callback
This commit is contained in:
commit
e73e604177
3 changed files with 35 additions and 6 deletions
|
@ -52,14 +52,28 @@ Widget createScaffold() {
|
|||
return 'False!';
|
||||
}
|
||||
},
|
||||
onChanged: (value) {
|
||||
if (value) {
|
||||
print("ListTile Checked :)");
|
||||
} else {
|
||||
print("ListTile Not Checked :(");
|
||||
}
|
||||
},
|
||||
),
|
||||
CheckboxIconFormField(
|
||||
initialValue: true,
|
||||
enabled: false,
|
||||
iconSize: 32,
|
||||
onSaved: (bool? value) {},
|
||||
onChanged: (value) {
|
||||
if (value) {
|
||||
print("Icon Checked :)");
|
||||
} else {
|
||||
print("Icon Not Checked :(");
|
||||
}
|
||||
},
|
||||
),
|
||||
RaisedButton(
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
if (_formKey.currentState!.validate()) {
|
||||
_formKey.currentState!.save();
|
||||
|
|
|
@ -7,6 +7,7 @@ class CheckboxIconFormField extends FormField<bool> {
|
|||
BuildContext? context,
|
||||
FormFieldSetter<bool>? onSaved,
|
||||
bool initialValue = false,
|
||||
ValueChanged<bool>? onChanged,
|
||||
AutovalidateMode? autovalidateMode,
|
||||
bool enabled = true,
|
||||
IconData trueIcon = Icons.check,
|
||||
|
@ -29,19 +30,27 @@ class CheckboxIconFormField extends FormField<bool> {
|
|||
return Padding(
|
||||
padding: EdgeInsets.all(padding),
|
||||
child: state.value!
|
||||
? _createTappableIcon(state, enabled, trueIcon,
|
||||
? _createTappableIcon(state, enabled, trueIcon, onChanged,
|
||||
trueIconColor, disabledColor, iconSize)
|
||||
: _createTappableIcon(state, enabled, falseIcon,
|
||||
: _createTappableIcon(state, enabled, falseIcon, onChanged,
|
||||
falseIconColor, disabledColor, iconSize));
|
||||
},
|
||||
);
|
||||
|
||||
static Widget _createTappableIcon(FormFieldState<bool> state, bool enabled,
|
||||
IconData icon, Color? iconColor, Color? disabledColor, double? iconSize) {
|
||||
static Widget _createTappableIcon(
|
||||
FormFieldState<bool> state,
|
||||
bool enabled,
|
||||
IconData icon,
|
||||
ValueChanged<bool>? onChanged,
|
||||
Color? iconColor,
|
||||
Color? disabledColor,
|
||||
double? iconSize,
|
||||
) {
|
||||
return IconButton(
|
||||
onPressed: enabled
|
||||
? () {
|
||||
state.didChange(!state.value!);
|
||||
if (onChanged != null) onChanged(state.value!);
|
||||
}
|
||||
: null,
|
||||
icon: Icon(icon,
|
||||
|
|
|
@ -9,6 +9,7 @@ class CheckboxListTileFormField extends FormField<bool> {
|
|||
FormFieldSetter<bool>? onSaved,
|
||||
FormFieldValidator<bool>? validator,
|
||||
bool initialValue = false,
|
||||
ValueChanged<bool>? onChanged,
|
||||
AutovalidateMode? autovalidateMode,
|
||||
bool enabled = true,
|
||||
bool dense = false,
|
||||
|
@ -33,7 +34,12 @@ class CheckboxListTileFormField extends FormField<bool> {
|
|||
activeColor: activeColor,
|
||||
checkColor: checkColor,
|
||||
value: state.value,
|
||||
onChanged: enabled ? state.didChange : null,
|
||||
onChanged: enabled
|
||||
? (value) {
|
||||
state.didChange(value);
|
||||
if (onChanged != null) onChanged(value!);
|
||||
}
|
||||
: null,
|
||||
subtitle: state.hasError
|
||||
? Text(
|
||||
state.errorText!,
|
||||
|
|
Loading…
Reference in a new issue