toggleable property
Set to true if this radio list tile 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, RadioGroup.onChanged is called with value when selected while RadioGroup.groupValue != value, and with null when selected again while RadioGroup.groupValue == value.
If false, RadioGroup.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 RadioGroup.groupValue) can this radio list tile be unselected.
The default is false.
This example shows how to enable deselecting a radio button by setting the toggleable attribute.
To see it in action, copy and run this code snippet on DartPad.
import 'package:material_ui/material_ui.dart';
/// Flutter code sample for [RadioListTile.toggleable].
void main() => runApp(const RadioListTileApp());
class RadioListTileApp extends StatelessWidget {
const RadioListTileApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: const Text('RadioListTile.toggleable Sample')),
body: const RadioListTileExample(),
),
);
}
}
class RadioListTileExample extends StatefulWidget {
const RadioListTileExample({super.key});
@override
State<RadioListTileExample> createState() => _RadioListTileExampleState();
}
class _RadioListTileExampleState extends State<RadioListTileExample> {
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: RadioGroup<int>(
groupValue: groupValue,
onChanged: (int? value) {
setState(() {
groupValue = value;
});
},
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return RadioListTile<int>(
value: index,
toggleable: true,
title: Text(selections[index]),
);
},
itemCount: selections.length,
),
),
);
}
}
Implementation
// TODO(framework): Replace the following block with a @dartpad directive
// when it's supported. https://github.com/dart-lang/dartdoc/issues/4123
/// {@macro material_ui.dartpad_guide}
///
/// {@example /example/lib/radio_list_tile/radio_list_tile.toggleable.0.dart#body}
///
/// </callout-box>
final bool toggleable;