onChanged property

ValueChanged<double>? onChanged
final

Called during a drag when the user is selecting a new value for the slider by dragging.

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

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

link
Slider(
  value: _duelCommandment.toDouble(),
  min: 1.0,
  max: 10.0,
  divisions: 10,
  label: '$_duelCommandment',
  onChanged: (double newValue) {
    setState(() {
      _duelCommandment = newValue.round();
    });
  },
)

See also:

  • onChangeStart for a callback that is called when the user starts changing the value.
  • onChangeEnd for a callback that is called when the user stops changing the value.

Implementation

final ValueChanged<double>? onChanged;