onChanged property

ValueChanged<bool>? onChanged
final

Called when the radio should change between selected and de-selected states.

When the radio is tapped, then the onChanged callback, if set, will be applied to !selected (see selectedStyle).

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

The callback provided to onChanged should update the state of the parent StatefulWidget using the State.setState method, so that the parent gets rebuilt.

{@tool snippet}

A StatefulWidget that illustrates use of onSelected in an Radio.

class Wood extends StatefulWidget {
  const Wood({Key? key}) : super(key: key);

  @override
  State<StatefulWidget> createState() => WoodState();
}

class WoodState extends State<Wood> {
  bool _useChisel = false;

  @override
  Widget build(BuildContext context) {
    return Chip(
      label: const Text('Use Chisel'),
      selected: _useChisel,
      onSelected: (bool newValue) {
        setState(() {
          _useChisel = newValue;
        });
      },
    );
  }
}

{@end-tool}

Implementation

final ValueChanged<bool>? onChanged;