Skip to content

Commit c7ce24d

Browse files
authored
Update ListTile and ListTile based widget docs for Material usage (flutter#107104)
1 parent a2c2d1a commit c7ce24d

File tree

4 files changed

+107
-14
lines changed

4 files changed

+107
-14
lines changed

packages/flutter/lib/src/material/checkbox_list_tile.dart

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,35 @@ import 'theme_data.dart';
3939
/// [secondary] widget is placed on the opposite side. This maps to the
4040
/// [ListTile.leading] and [ListTile.trailing] properties of [ListTile].
4141
///
42+
/// This widget requires a [Material] widget ancestor in the tree to paint
43+
/// itself on, which is typically provided by the app's [Scaffold].
44+
/// The [tileColor], and [selectedTileColor] are not painted by the
45+
/// [CheckboxListTile] itself but by the [Material] widget ancestor.
46+
/// In this case, one can wrap a [Material] widget around the [CheckboxListTile],
47+
/// e.g.:
48+
///
49+
/// {@tool snippet}
50+
/// ```dart
51+
/// Container(
52+
/// color: Colors.green,
53+
/// child: Material(
54+
/// child: CheckboxListTile(
55+
/// tileColor: Colors.red,
56+
/// title: const Text('CheckboxListTile with red background'),
57+
/// value: true,
58+
/// onChanged:(bool? value) { },
59+
/// ),
60+
/// ),
61+
/// )
62+
/// ```
63+
/// {@end-tool}
64+
///
65+
/// ## Performance considerations when wrapping [CheckboxListTile] with [Material]
66+
///
67+
/// Wrapping a large number of [CheckboxListTile]s individually with [Material]s
68+
/// is expensive. Consider only wrapping the [CheckboxListTile]s that require it
69+
/// or include a common [Material] ancestor where possible.
70+
///
4271
/// To show the [CheckboxListTile] as disabled, pass null as the [onChanged]
4372
/// callback.
4473
///

packages/flutter/lib/src/material/list_tile.dart

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,28 +87,32 @@ enum ListTileControlAffinity {
8787
/// List tiles are typically used in [ListView]s, or arranged in [Column]s in
8888
/// [Drawer]s and [Card]s.
8989
///
90-
/// One ancestor must be a [Material] widget and typically this is
91-
/// provided by the app's [Scaffold]. The [tileColor],
92-
/// [selectedTileColor], [focusColor], and [hoverColor] are not
93-
/// painted by the list tile itself but by the material widget
94-
/// ancestor. This generally has no effect. However, if an opaque
95-
/// widget, like `Container(color: Colors.white)`, is included in
96-
/// between the [ListTile] and its [Material] ancestor, then the
97-
/// opaque widget will obscure the material widget and its background
98-
/// [tileColor], etc. If this a problem, one can wrap a [Material]
99-
/// widget around the list tile, e.g.:
90+
/// This widget requires a [Material] widget ancestor in the tree to paint
91+
/// itself on, which is typically provided by the app's [Scaffold].
92+
/// The [tileColor], [selectedTileColor], [focusColor], and [hoverColor]
93+
/// are not painted by the [ListTile] itself but by the [Material] widget
94+
/// ancestor. In this case, one can wrap a [Material] widget around the
95+
/// [ListTile], e.g.:
10096
///
97+
/// {@tool snippet}
10198
/// ```dart
10299
/// Container(
103100
/// color: Colors.green,
104-
/// child: Material(
101+
/// child: const Material(
105102
/// child: ListTile(
106-
/// title: const Text('ListTile with red background'),
103+
/// title: Text('ListTile with red background'),
107104
/// tileColor: Colors.red,
108105
/// ),
109106
/// ),
110107
/// )
111108
/// ```
109+
/// {@end-tool}
110+
///
111+
/// ## Performance considerations when wrapping [ListTile] with [Material]
112+
///
113+
/// Wrapping a large number of [ListTile]s individually with [Material]s
114+
/// is expensive. Consider only wrapping the [ListTile]s that require it
115+
/// or include a common [Material] ancestor where possible.
112116
///
113117
/// {@tool snippet}
114118
///

packages/flutter/lib/src/material/radio_list_tile.dart

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ import 'theme_data.dart';
1212

1313
// Examples can assume:
1414
// void setState(VoidCallback fn) { }
15+
// enum Meridiem { am, pm }
1516

1617
/// A [ListTile] with a [Radio]. In other words, a radio button with a label.
1718
///
@@ -40,6 +41,35 @@ import 'theme_data.dart';
4041
/// [secondary] widget is placed on the opposite side. This maps to the
4142
/// [ListTile.leading] and [ListTile.trailing] properties of [ListTile].
4243
///
44+
/// This widget requires a [Material] widget ancestor in the tree to paint
45+
/// itself on, which is typically provided by the app's [Scaffold].
46+
/// The [tileColor], and [selectedTileColor] are not painted by the
47+
/// [RadioListTile] itself but by the [Material] widget ancestor. In this
48+
/// case, one can wrap a [Material] widget around the [RadioListTile], e.g.:
49+
///
50+
/// {@tool snippet}
51+
/// ```dart
52+
/// Container(
53+
/// color: Colors.green,
54+
/// child: Material(
55+
/// child: RadioListTile<Meridiem>(
56+
/// tileColor: Colors.red,
57+
/// title: const Text('AM'),
58+
/// groupValue: Meridiem.am,
59+
/// value: Meridiem.am,
60+
/// onChanged:(Meridiem? value) { },
61+
/// ),
62+
/// ),
63+
/// )
64+
/// ```
65+
/// {@end-tool}
66+
///
67+
/// ## Performance considerations when wrapping [RadioListTile] with [Material]
68+
///
69+
/// Wrapping a large number of [RadioListTile]s individually with [Material]s
70+
/// is expensive. Consider only wrapping the [RadioListTile]s that require it
71+
/// or include a common [Material] ancestor where possible.
72+
///
4373
/// To show the [RadioListTile] as disabled, pass null as the [onChanged]
4474
/// callback.
4575
///

packages/flutter/lib/src/material/switch_list_tile.dart

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import 'theme_data.dart';
1212

1313
// Examples can assume:
1414
// void setState(VoidCallback fn) { }
15-
// bool _isSelected;
15+
// bool _isSelected = true;
1616

1717
enum _SwitchListTileType { material, adaptive }
1818

@@ -47,6 +47,34 @@ enum _SwitchListTileType { material, adaptive }
4747
/// in the [ListTile.trailing] slot) which can be changed using [controlAffinity].
4848
/// The [secondary] widget is placed in the [ListTile.leading] slot.
4949
///
50+
/// This widget requires a [Material] widget ancestor in the tree to paint
51+
/// itself on, which is typically provided by the app's [Scaffold].
52+
/// The [tileColor], and [selectedTileColor] are not painted by the
53+
/// [SwitchListTile] itself but by the [Material] widget ancestor. In this
54+
/// case, one can wrap a [Material] widget around the [SwitchListTile], e.g.:
55+
///
56+
/// {@tool snippet}
57+
/// ```dart
58+
/// Container(
59+
/// color: Colors.green,
60+
/// child: Material(
61+
/// child: SwitchListTile(
62+
/// tileColor: Colors.red,
63+
/// title: const Text('SwitchListTile with red background'),
64+
/// value: true,
65+
/// onChanged:(bool? value) { },
66+
/// ),
67+
/// ),
68+
/// )
69+
/// ```
70+
/// {@end-tool}
71+
///
72+
/// ## Performance considerations when wrapping [SwitchListTile] with [Material]
73+
///
74+
/// Wrapping a large number of [SwitchListTile]s individually with [Material]s
75+
/// is expensive. Consider only wrapping the [SwitchListTile]s that require it
76+
/// or include a common [Material] ancestor where possible.
77+
///
5078
/// To show the [SwitchListTile] as disabled, pass null as the [onChanged]
5179
/// callback.
5280
///
@@ -217,6 +245,7 @@ class SwitchListTile extends StatelessWidget {
217245
/// [StatefulWidget] using the [State.setState] method, so that the parent
218246
/// gets rebuilt; for example:
219247
///
248+
/// {@tool snippet}
220249
/// ```dart
221250
/// SwitchListTile(
222251
/// value: _isSelected,
@@ -225,9 +254,10 @@ class SwitchListTile extends StatelessWidget {
225254
/// _isSelected = newValue;
226255
/// });
227256
/// },
228-
/// title: Text('Selection'),
257+
/// title: const Text('Selection'),
229258
/// )
230259
/// ```
260+
/// {@end-tool}
231261
final ValueChanged<bool>? onChanged;
232262

233263
/// The color to use when this switch is on.

0 commit comments

Comments
 (0)