Skip to content

Commit d4c4f56

Browse files
authored
Added assert to prevent complete ListTile trailing/leading horizontal expansion (flutter#30212)
1 parent 712195b commit d4c4f56

File tree

1 file changed

+16
-5
lines changed

1 file changed

+16
-5
lines changed

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

+16-5
Original file line numberDiff line numberDiff line change
@@ -165,12 +165,15 @@ enum ListTileControlAffinity {
165165
/// wraps to two lines (if it is true).
166166
///
167167
/// The heights of the [leading] and [trailing] widgets are constrained
168-
/// according to the [Material spec]
169-
/// (https://material.io/design/components/lists.html).
168+
/// according to the
169+
/// [Material spec](https://material.io/design/components/lists.html).
170170
/// An exception is made for one-line ListTiles for accessibility. Please
171171
/// see the example below to see how to adhere to both Material spec and
172172
/// accessibility requirements.
173173
///
174+
/// Note that [leading] and [trailing] widgets can expand as far as they wish
175+
/// horizontally, so ensure that they are properly constrained.
176+
///
174177
/// List tiles are typically used in [ListView]s, or arranged in [Column]s in
175178
/// [Drawer]s and [Card]s.
176179
///
@@ -218,13 +221,13 @@ enum ListTileControlAffinity {
218221
/// that are large enough, but it is up to the developer to ensure that
219222
/// their widgets follow the Material spec.
220223
///
221-
/// The following is an example of a one-line, non-[dense] ListTile with a
224+
/// {@tool sample}
225+
///
226+
/// Here is an example of a one-line, non-[dense] ListTile with a
222227
/// tappable leading widget that adheres to accessibility requirements and
223228
/// the Material spec. To adjust the use case below for a one-line, [dense]
224229
/// ListTile, adjust the vertical padding to 8.0.
225230
///
226-
/// {@tool sample}
227-
///
228231
/// ```dart
229232
/// ListTile(
230233
/// leading: GestureDetector(
@@ -984,6 +987,14 @@ class _RenderListTile extends RenderBox {
984987
final double tileWidth = looseConstraints.maxWidth;
985988
final Size leadingSize = _layoutBox(leading, iconConstraints);
986989
final Size trailingSize = _layoutBox(trailing, iconConstraints);
990+
assert(
991+
tileWidth != leadingSize.width,
992+
'Leading widget consumes entire tile width. Please use a sized widget.'
993+
);
994+
assert(
995+
tileWidth != trailingSize.width,
996+
'Trailing widget consumes entire tile width. Please use a sized widget.'
997+
);
987998

988999
final double titleStart = hasLeading
9891000
? math.max(_minLeadingWidth, leadingSize.width) + _horizontalTitleGap

0 commit comments

Comments
 (0)