onChanged property
final
Called when the value of the checkbox should change.
The checkbox passes the new value to the callback but does not actually change state until the parent widget rebuilds the checkbox with the new value.
If this callback is null, the menu item will be displayed as disabled and will not respond to input gestures.
When the checkbox is tapped, if tristate is false (the default) then the
onChanged callback will be applied to !value
. If tristate is true
this callback cycle from false to true to null and then back to false
again.
The callback provided to onChanged should update the state of the parent StatefulWidget using the State.setState method, so that the parent gets rebuilt; for example:
CheckboxMenuButton(
value: _throwShotAway,
child: const Text('THROW'),
onChanged: (bool? newValue) {
setState(() {
_throwShotAway = newValue!;
});
},
)
Implementation
final ValueChanged<bool?>? onChanged;