Unverified Commit d4c4f563 authored by Shi-Hao Hong's avatar Shi-Hao Hong Committed by GitHub

Added assert to prevent complete ListTile trailing/leading horizontal expansion (#30212)

parent 712195b5
...@@ -165,12 +165,15 @@ enum ListTileControlAffinity { ...@@ -165,12 +165,15 @@ enum ListTileControlAffinity {
/// wraps to two lines (if it is true). /// wraps to two lines (if it is true).
/// ///
/// The heights of the [leading] and [trailing] widgets are constrained /// The heights of the [leading] and [trailing] widgets are constrained
/// according to the [Material spec] /// according to the
/// (https://material.io/design/components/lists.html). /// [Material spec](https://material.io/design/components/lists.html).
/// An exception is made for one-line ListTiles for accessibility. Please /// 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 /// see the example below to see how to adhere to both Material spec and
/// accessibility requirements. /// 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 /// List tiles are typically used in [ListView]s, or arranged in [Column]s in
/// [Drawer]s and [Card]s. /// [Drawer]s and [Card]s.
/// ///
...@@ -218,13 +221,13 @@ enum ListTileControlAffinity { ...@@ -218,13 +221,13 @@ enum ListTileControlAffinity {
/// that are large enough, but it is up to the developer to ensure that /// that are large enough, but it is up to the developer to ensure that
/// their widgets follow the Material spec. /// 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 /// tappable leading widget that adheres to accessibility requirements and
/// the Material spec. To adjust the use case below for a one-line, [dense] /// the Material spec. To adjust the use case below for a one-line, [dense]
/// ListTile, adjust the vertical padding to 8.0. /// ListTile, adjust the vertical padding to 8.0.
/// ///
/// {@tool sample}
///
/// ```dart /// ```dart
/// ListTile( /// ListTile(
/// leading: GestureDetector( /// leading: GestureDetector(
...@@ -984,6 +987,14 @@ class _RenderListTile extends RenderBox { ...@@ -984,6 +987,14 @@ class _RenderListTile extends RenderBox {
final double tileWidth = looseConstraints.maxWidth; final double tileWidth = looseConstraints.maxWidth;
final Size leadingSize = _layoutBox(leading, iconConstraints); final Size leadingSize = _layoutBox(leading, iconConstraints);
final Size trailingSize = _layoutBox(trailing, 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 final double titleStart = hasLeading
? math.max(_minLeadingWidth, leadingSize.width) + _horizontalTitleGap ? math.max(_minLeadingWidth, leadingSize.width) + _horizontalTitleGap
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment