onChanged property

ValueChanged<bool> onChanged
final

Called when the user toggles the switch on or off.

The switch passes the new value to the callback but does not actually change state until the parent widget rebuilds the switch tile with the new value.

If null, the switch 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:

SwitchListTile(
  value: _isSelected,
  onChanged: (bool newValue) {
    setState(() {
      _isSelected = newValue;
    });
  },
  title: Text('Selection'),
)

Implementation

final ValueChanged<bool> onChanged