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 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:

Switch(
  value: _giveVerse,
  onChanged: (bool newValue) {
    setState(() {
      _giveVerse = newValue;
    });
  },
)

Implementation

final ValueChanged<bool> onChanged