From d4c4f563c4148709e38a52efed5e949780d11f7f Mon Sep 17 00:00:00 2001 From: Shi-Hao Hong Date: Mon, 1 Apr 2019 17:41:56 -0700 Subject: [PATCH] Added assert to prevent complete ListTile trailing/leading horizontal expansion (#30212) --- .../flutter/lib/src/material/list_tile.dart | 21 ++++++++++++++----- 1 file changed, 16 insertions(+), 5 deletions(-) diff --git a/packages/flutter/lib/src/material/list_tile.dart b/packages/flutter/lib/src/material/list_tile.dart index 998a877c6e..340f65defe 100644 --- a/packages/flutter/lib/src/material/list_tile.dart +++ b/packages/flutter/lib/src/material/list_tile.dart @@ -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