toggleable property

bool toggleable
final

Set to true if this radio button is allowed to be returned to an indeterminate state by selecting it again when selected.

To indicate returning to an indeterminate state, onChanged will be called with null.

If true, onChanged can be called with value when selected while groupValue != value, or with null when selected again while groupValue == value.

If false, onChanged will be called with value when it is selected while groupValue != value, and only by selecting another radio button in the group (i.e. changing the value of groupValue) can this radio button be unselected.

The default is false.

{@tool dartpad --template=stateful_widget_scaffold} This example shows how to enable deselecting a radio button by setting the toggleable attribute.

int? groupValue;
static const List<String> selections = <String>[
  'Hercules Mulligan',
  'Eliza Hamilton',
  'Philip Schuyler',
  'Maria Reynolds',
  'Samuel Seabury',
];

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: ListView.builder(
      itemBuilder: (BuildContext context, int index) {
        return Row(
          mainAxisSize: MainAxisSize.min,
          crossAxisAlignment: CrossAxisAlignment.center,
          children: <Widget>[
            Radio<int>(
                value: index,
                groupValue: groupValue,
                // TRY THIS: Try setting the toggleable value to false and
                // see how that changes the behavior of the widget.
                toggleable: true,
                onChanged: (int? value) {
                  setState(() {
                    groupValue = value;
                  });
                }),
            Text(selections[index]),
          ],
        );
      },
      itemCount: selections.length,
    ),
  );
}

{@end-tool}

Implementation

final bool toggleable;