Add Material 3 CheckboxListTile example and update existing examples (#118792)
* Add Material 3 `CheckboxListTile` example and update existing examples * fix `list_tile.dart` doc issues * Remove unnecessary comma
This commit is contained in:
@@ -27,7 +27,7 @@ class ListTileExample extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('ListTile Sample')),
|
||||
body: Column(
|
||||
body: ListView(
|
||||
children: const <Widget>[
|
||||
ListTile(
|
||||
leading: CircleAvatar(
|
||||
@@ -37,7 +37,7 @@ class ListTileExample extends StatelessWidget {
|
||||
subtitle: Text('Supporting text'),
|
||||
trailing: Icon(Icons.favorite_rounded),
|
||||
),
|
||||
Divider(),
|
||||
Divider(height: 0),
|
||||
ListTile(
|
||||
leading: CircleAvatar(
|
||||
child: Text('B')
|
||||
@@ -46,7 +46,7 @@ class ListTileExample extends StatelessWidget {
|
||||
subtitle: Text('Longer supporting text to demonstrate how the text wraps and how the leading and trailing widgets are centered vertically with the text.'),
|
||||
trailing: Icon(Icons.favorite_rounded),
|
||||
),
|
||||
Divider(),
|
||||
Divider(height: 0),
|
||||
ListTile(
|
||||
leading: CircleAvatar(
|
||||
child: Text('C')
|
||||
@@ -56,7 +56,7 @@ class ListTileExample extends StatelessWidget {
|
||||
trailing: Icon(Icons.favorite_rounded),
|
||||
isThreeLine: true,
|
||||
),
|
||||
Divider(),
|
||||
Divider(height: 0),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -35,54 +35,51 @@ class _ListTileExampleState extends State<ListTileExample> {
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text('ListTile Sample')),
|
||||
body: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
ListTile(
|
||||
enabled: _enabled,
|
||||
selected: _selected,
|
||||
onTap: () {
|
||||
body: Center(
|
||||
child: ListTile(
|
||||
enabled: _enabled,
|
||||
selected: _selected,
|
||||
onTap: () {
|
||||
setState(() {
|
||||
// This is called when the user toggles the switch.
|
||||
_selected = !_selected;
|
||||
});
|
||||
},
|
||||
// This sets text color and icon color to red when list tile is disabled and
|
||||
// green when list tile is selected, otherwise sets it to black.
|
||||
iconColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return Colors.red;
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return Colors.green;
|
||||
}
|
||||
return Colors.black;
|
||||
}),
|
||||
// This sets text color and icon color to red when list tile is disabled and
|
||||
// green when list tile is selected, otherwise sets it to black.
|
||||
textColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return Colors.red;
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return Colors.green;
|
||||
}
|
||||
return Colors.black;
|
||||
}),
|
||||
leading: const Icon(Icons.person),
|
||||
title: const Text('Headline'),
|
||||
subtitle: Text('Enabled: $_enabled, Selected: $_selected'),
|
||||
trailing: Switch(
|
||||
onChanged: (bool? value) {
|
||||
// This is called when the user toggles the switch.
|
||||
setState(() {
|
||||
// This is called when the user toggles the switch.
|
||||
_selected = !_selected;
|
||||
_enabled = value!;
|
||||
});
|
||||
},
|
||||
// This sets text color and icon color to red when list tile is disabled and
|
||||
// green when list tile is selected, otherwise sets it to black.
|
||||
iconColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return Colors.red;
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return Colors.green;
|
||||
}
|
||||
return Colors.black;
|
||||
}),
|
||||
// This sets text color and icon color to red when list tile is disabled and
|
||||
// green when list tile is selected, otherwise sets it to black.
|
||||
textColor: MaterialStateColor.resolveWith((Set<MaterialState> states) {
|
||||
if (states.contains(MaterialState.disabled)) {
|
||||
return Colors.red;
|
||||
}
|
||||
if (states.contains(MaterialState.selected)) {
|
||||
return Colors.green;
|
||||
}
|
||||
return Colors.black;
|
||||
}),
|
||||
leading: const Icon(Icons.person),
|
||||
title: const Text('Headline'),
|
||||
subtitle: Text('Enabled: $_enabled, Selected: $_selected'),
|
||||
trailing: Switch(
|
||||
onChanged: (bool? value) {
|
||||
// This is called when the user toggles the switch.
|
||||
setState(() {
|
||||
_enabled = value!;
|
||||
});
|
||||
},
|
||||
value: _enabled,
|
||||
),
|
||||
value: _enabled,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user