onChanged property Null safety

ValueChanged<bool?>? onChanged

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 checkbox 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.

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:

  value: _throwShotAway,
  onChanged: (bool? newValue) {
    setState(() {
      _throwShotAway = newValue!;


final ValueChanged<bool?>? onChanged;