onSelected property

ValueChanged<bool>? get onSelected

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

When the chip is tapped, then the onSelected callback, if set, will be applied to !selected (see selected).

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

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

The onSelected and TappableChipAttributes.onPressed callbacks must not both be specified at the same time.

A StatefulWidget that illustrates use of onSelected in an InputChip.
link
class Wood extends StatefulWidget {
  const Wood({super.key});

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

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

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

Implementation

ValueChanged<bool>? get onSelected;