onChanged property

ValueChanged<bool?>? onChanged
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 tile with the new value.

If null, the checkbox will be displayed as disabled.

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:

CheckboxListTile(
  value: _throwShotAway,
  onChanged: (bool? newValue) {
    setState(() {
      _throwShotAway = newValue;
    });
  },
  title: const Text('Throw away your shot'),
)

Implementation

// TODO(framework): Add unit tests to this code snippet.
// https://github.com/flutter/flutter/issues/188530
///
/// 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:
///
/// ```dart
/// CheckboxListTile(
///   value: _throwShotAway,
///   onChanged: (bool? newValue) {
///     setState(() {
///       _throwShotAway = newValue;
///     });
///   },
///   title: const Text('Throw away your shot'),
/// )
/// ```
///
/// </callout-box>
final ValueChanged<bool?>? onChanged;