Skip to content

Conversation

@HansMuller
Copy link
Contributor

Updated ListTile's layout to match the current Material spec: https://material.io/design/components/lists.html#specs

Unless textScaleFactor causes the layout to overflow, the title and subtitle baselines are now located per the spec. Similarly the height of the tile and the layout of the title/subtitle relative to the leading widget are as specified.

Added a contentPadding parameter to ListTileTheme and ListTile to enable overriding the default 16dps padding on the tile's left and right .

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I first read this, I was thinking that it specified the same padding for each of the items in the list tile separately, meaning that if you set it to 10.0, then there would be 20 pixels horizontally between the leading widget and the titles. It looks like this doesn't do that, but rather puts padding around the outside of the entire widget only, not the individual components (so setting it to 10.0 wouldn't affect internal horizontal padding). You might clear up the wording a bit.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I guess that's the confusing difference between the ListTiles' padding and the ListTile's padding.

I've changed it to:

  /// The tile's internal padding.
  ///
  /// Insets a [ListTile]'s contents: its [leading], [title], [subtitle],
  /// and [trailing] widgets.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment as above to clarify what it affects.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to have the safe area outside of the padding? This way it might look a little close to a side notch if it's at the edge. And why only have it take effect horizontally?

Copy link
Contributor Author

@HansMuller HansMuller May 11, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The safe area has been within the padding and configured this way for about 6 months; since #13545

Maybe we should leave it alone?

@cbracken what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you make these magic numbers into named constants?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto here, and below.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I haven't introduced one-time constants for the default tile heights and baselines because making up names for these values doesn't seems to make the code any more readable.

I did add a general comment about the dimensions and a pointer to the MD spec

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yay! We can add pointers to the MD spec again!

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe convert this magic number into a named constant?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some of these (like this one) are only used once. It might be simpler to just have leading != null for that one conditional.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I had it that way at one point but I found it easier to read/change the code by defining hasFoo vars for all of the children

@HansMuller HansMuller force-pushed the updated_list_tile_layout branch from abfb2ae to ae94811 Compare May 11, 2018 19:55
final Decoration decoration = new BoxDecoration(
border: new Border(
bottom: Divider.createBorderSide(context, color: color),
border: new Border(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation is only one space: should be two.

while (iterator.moveNext()) {
yield new DecoratedBox(
position: DecorationPosition.foreground,
position: DecorationPosition.foreground,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

position: DecorationPosition.foreground,
decoration: decoration,
child: tile,
child: tile,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for catching these indentOs. I must be developing indentation blindness :-)


final double titleStart = hasLeading ? leadingSize.width <= 40.0 ? 56.0 : leadingSize.width + 16.0 : 0.0;
final BoxConstraints textConstraints = looseConstraints.tighten(
width: tileWidth - titleStart - (hasTrailing ? trailingSize.width + 16.0 : 0.0),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should that 16.0 also be _leadingTitleGap? (in which case it should probably be called _titleGap, or add a _trailingTitleGap).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point. I used _kTitleGap

case TextDirection.rtl: {
if (hasLeading)
_positionBox(leading, new Offset(tileWidth - leadingSize.width, leadingY));
final double titleX = hasTrailing ? trailingSize.width + 16.0 : 0.0;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this 16.0 should also be a named constant (e.g. _titleGap) to keep it consistent with the one above.

@gspencergoog
Copy link
Contributor

32384589-a60f0e74-c078-11e7-9bc1-e5b5287aea9d
(modulo nits)

@HansMuller HansMuller merged commit ee019c0 into flutter:master May 14, 2018
@HansMuller HansMuller deleted the updated_list_tile_layout branch May 14, 2018 15:23
DaveShuckerow pushed a commit to DaveShuckerow/flutter that referenced this pull request May 14, 2018
static const double _kTitleGap = 16.0; // between the titles and the leading/trailing widgets

final Map<_ListTileSlot, RenderBox> slotToChild = <_ListTileSlot, RenderBox>{};
final Map<RenderBox, _ListTileSlot> childToSlot = <RenderBox, _ListTileSlot>{};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is a pattern we've seen several times now, we might want to factor it out into a common foundation class

}

@override
bool get sizedByParent => false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

isn't this the default?


if (isOneLine)
return isDense ? 48.0 : 56.0;
else if (isTwoLine)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these elses can be omitted

}
}

class _RenderListTileElement extends RenderObjectElement {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

generally speaking, we put the element with the widget, and the renderobject after (or before) them.

tileHeight = titleSize.height + subtitleSize.height;
titleY = 0.0;
subtitleY = titleSize.height;
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What are lines 780 to 795 based on?

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Aug 8, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants