-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
RenderConstrainedBox takes constraints when measuring intrinsic sizes #162809
base: master
Are you sure you want to change the base?
RenderConstrainedBox takes constraints when measuring intrinsic sizes #162809
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption, contact "@test-exemption-reviewer" in the #hackers channel in Discord (don't just cc them here, they won't see it!). If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix? Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. The test exemption team is a small volunteer group, so all reviewers should feel empowered to ask for tests, without delegating that responsibility entirely to the test exemption group. |
CC @victorsanni from triage. |
Previous fix deemed too breaking: #137874 |
So, just to get this straight: |
See this comment. I'm curious what the internal failures looked like.
To me |
That is exactly the comment I am referring to. Would really like to know too.
I believe I tried that and got to the conclusion I didn't want to clamp the height and width, but rather just constrain max size. |
I looked into the internal test failures from the other PR, now I'm convinced that using Looks like this change still breaks internal golden tests but most of these changes look like improvements so far. There are a couple of golden changes that I need to further investigate. |
final double width = super.computeMinIntrinsicWidth(height); | ||
|
||
final double width = super.computeMinIntrinsicWidth( | ||
min(_additionalConstraints.maxHeight, height), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: this could be a bit confusing to future readers, could you add a comment regarding why using min
here instead of also taking _additionalConstraints.minHeight
into account?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems not addressed yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm hopeful the comment is clear enough, and not too long.
Hmm there's a legit internal failure. The problem is that, if the parent that has a set of tight constraints, a child For example, in a render tree like this: RenderBox( // A RenderBox that gives tight width constraints to its child. In the failing test it was a Column with `CrossAxisAlignment.stretch`.
constraints: BoxConstraints.tight(width: x),
child: RenderConstrainedBox(
additionalConstraints: BoxConstraints(minWidth: 200, maxWidth: 250),
child: ...
),
); The |
I think the current behavior is correct. If using intrinsic size, it is not Do you have a link to the error? |
To clarify: Are you confirming my PR implementation is correct, or the current production code? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the code LGTM except the open comment
final double width = super.computeMinIntrinsicWidth(height); | ||
|
||
final double width = super.computeMinIntrinsicWidth( | ||
min(_additionalConstraints.maxHeight, height), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems not addressed yet.
would also need to rebase to pass the ci |
Hi @lohnn looks like there is some formatting issue https://logs.chromium.org/logs/flutter/buildbucket/cr-buildbucket/8720576242602713249/+/u/run_test.dart_for_analyze_shard_and_subshard_None/stdout?format=raw |
I spoke with @goderbauer offline he pointed out in the getMaxIntrinsicHeight documentation it says:
So the incoming But at the same time there are places that the incoming height is interpreted as a
which seems to imply that |
So if the first interpretation is true, then the current |
Is this true? The doc doesn't suggest that.I thought the getIntrinsicHight is more of |
This is also what I thought, and this is also causing real layout bugs where intrinsic (expected) sizes are not matching the actual size. |
I totally agree that this is a real layout but, but applying this patch will unfortunately introduce real layout bugs too, which you can repro by just changing the CustomScrollView(
slivers: [
SliverFillRemaining(
hasScrollBody: false,
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: const [
SizedBox(
width: 300,
child: Text(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec commodo arcu nec varius ultricies. Vestibulum ante ipsum primis in faucibus orci luctus et ultrices posuere cubilia curae; Pellentesque porta auctor.',
),
),
],
),
),
],
); Of course it doesn't make a lot of sense when |
All right, I now see how we trade from one problem to another in this case. |
RenderConstrainedBox (such as used in SizedBox and ConstrainedBox) now takes constraints max sizes into consideration when measuring intrinsic sizes.
Fixes #162808.
Pre-launch Checklist
///
).If you need help, consider asking for advice on the #hackers-new channel on Discord.