Added assert to prevent complete ListTile trailing/leading horizontal expansion (#30212)
This commit is contained in:
@@ -165,12 +165,15 @@ enum ListTileControlAffinity {
|
||||
/// wraps to two lines (if it is true).
|
||||
///
|
||||
/// The heights of the [leading] and [trailing] widgets are constrained
|
||||
/// according to the [Material spec]
|
||||
/// (https://material.io/design/components/lists.html).
|
||||
/// according to the
|
||||
/// [Material spec](https://material.io/design/components/lists.html).
|
||||
/// An exception is made for one-line ListTiles for accessibility. Please
|
||||
/// see the example below to see how to adhere to both Material spec and
|
||||
/// accessibility requirements.
|
||||
///
|
||||
/// Note that [leading] and [trailing] widgets can expand as far as they wish
|
||||
/// horizontally, so ensure that they are properly constrained.
|
||||
///
|
||||
/// List tiles are typically used in [ListView]s, or arranged in [Column]s in
|
||||
/// [Drawer]s and [Card]s.
|
||||
///
|
||||
@@ -218,13 +221,13 @@ enum ListTileControlAffinity {
|
||||
/// that are large enough, but it is up to the developer to ensure that
|
||||
/// their widgets follow the Material spec.
|
||||
///
|
||||
/// The following is an example of a one-line, non-[dense] ListTile with a
|
||||
/// {@tool sample}
|
||||
///
|
||||
/// Here is an example of a one-line, non-[dense] ListTile with a
|
||||
/// tappable leading widget that adheres to accessibility requirements and
|
||||
/// the Material spec. To adjust the use case below for a one-line, [dense]
|
||||
/// ListTile, adjust the vertical padding to 8.0.
|
||||
///
|
||||
/// {@tool sample}
|
||||
///
|
||||
/// ```dart
|
||||
/// ListTile(
|
||||
/// leading: GestureDetector(
|
||||
@@ -984,6 +987,14 @@ class _RenderListTile extends RenderBox {
|
||||
final double tileWidth = looseConstraints.maxWidth;
|
||||
final Size leadingSize = _layoutBox(leading, iconConstraints);
|
||||
final Size trailingSize = _layoutBox(trailing, iconConstraints);
|
||||
assert(
|
||||
tileWidth != leadingSize.width,
|
||||
'Leading widget consumes entire tile width. Please use a sized widget.'
|
||||
);
|
||||
assert(
|
||||
tileWidth != trailingSize.width,
|
||||
'Trailing widget consumes entire tile width. Please use a sized widget.'
|
||||
);
|
||||
|
||||
final double titleStart = hasLeading
|
||||
? math.max(_minLeadingWidth, leadingSize.width) + _horizontalTitleGap
|
||||
|
||||
Reference in New Issue
Block a user