-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Remove explicit width from leading element in ListTile #12253
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
…istent with leading element)
|
Sorry, my relative inexperience w/ GitHub PRs is showing; only the last commit on this branch is relevant. I can restructure this so its on a branch with only commits related to this PR if needed. |
|
You can rely on the text widths not changing, we run the tests with a special font where the ASCII characters all have exactly the same width as the font height. |
|
I don't think we want to remove the leading width, it's intentionally there so that whether you have a leading widget or not, the labels are all aligned. We could add a way to configure that, though I'm not sure what a good name for it would be... |
|
Ah, right, I see. |
|
@zzzev Can you elaborate on your desire to remove the explicit width on the leading widget? |
|
@Hixie sorry for the delay. Removing the explicit width will allow the user to set a leading widget that's either narrower (probably not common) or wider (possibly more common, including e.g. in the test for this widget, which had text that overflowed the leading element's width) than 40dps. I also realized when thinking about this that as is this will actually cause a regression for existing ListTiles which contain only an icon, which currently pick up some additional whitespace via this explicit width. I think the ideal thing would be to add the padding for Icons to match the spec (which specifies that specifically icons and avatars should have the spacing that exists at head), and allow other Widgets to flow freely however they'd like, but I'm not sure that "looking into the leading" like that is necessarily a good idea. Since this all was in the name of consistency between trailing and leading elements, and not a concrete use case that we need, I'm ok with just dropping this PR if you think the current behavior is good. If you think that users should be able to have leading Widgets with a non-40dp-width, I can update this to do the is-leading-an-Icon check I mention above, let me know what you'd prefer. |
|
If this isn't a problem you are currently running into, I say we close it and wait for to solve it when we have a real problem so we can study it more carefully. I have no objection to making the leading widget's size more customisable. There's various ways we could do this (e.g. ListTileTheme, an argument, etc). Regarding the spacing not matching the material spec, I didn't quite understand what you meant but if you wouldn't mind filing a bug explaining the difference between what Flutter does and what the spec says we can definitely look into fixing this. |
|
To clarify: the spacing for ListTiles at head does match the spec for leading elements that are Icon or CircleAvatar widgets, but the code in this PR would cause a regression for Icons (CircleAvatars need no extra padding, so they'd be the look the same with this code). The spec doesn't have any examples of leading elements that aren't Icons or CircleAvatars, so I think it's an area of somewhat undefined expectations. I'll go ahead and close this PR for now and I'll revisit this if needed. |


This is (another) followup to ensure consistency between leading and trailing elements in ListTiles.
See related previous PRs:
#12221
#11858
Testing note: I think I am testing this well, but could also add more asserts that depend on the actual rendered width of the labels, instead of the (more definitively known) 16.0 width of the padding. I think it's probably preferable to depend only on the precisely set widths if possible to avoid breakages from e.g. text rendering changes.