Skip to content

Conversation

Albert221
Copy link
Contributor

RenderConstrainedBox was ignoring the additionalConstraints while calling the child's get{Min,Max}Intrinsic{Width,Height}. This was in my understanding wrong. The intrinsic dimensions are often used to make some layout calculations. But these dimensions can't be imaginary. They must be real. If we call for minimum intrinsic height given some width, then the widget should be able to lay itself out within tight constraints for the same width and height. This was not the case for widgets that we wrap in SizedBox or ConstrainedBox, because they were ignoring the constraints when passing down the known dimension when calling for intrinsic other dimension. This PR fixes that.

Fixes #137546.

Below are screenshots of before and after, given the code from the issue above.

Before After
image image

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

@github-actions github-actions bot added the framework flutter/packages/flutter repository. See also f: labels. label Nov 3, 2023
@Albert221 Albert221 changed the title Constrain dimensions passed down within RenderConstrainedBox Constrain dimensions passed down in intrinsic protocol within RenderConstrainedBox Nov 3, 2023
@goderbauer goderbauer force-pushed the render-constrained-box-intrinsics branch from 5fa3bd6 to ef62b31 Compare November 28, 2023 00:31
@goderbauer
Copy link
Member

(Trying to see how/what this will break in google's internal repository, will report back)

@Albert221
Copy link
Contributor Author

@goderbauer how's the progress? :)

@goderbauer
Copy link
Member

I had some time to look at this a little closer. I attempted exactly the same fix some time ago in #71880 and shortly after that figured out that doing just that wasn't enough as we have to consider infinity separately (#72095). Looks like the latter is missing from this PR.

Having said all that, my change was later reverted in #72102 because it broke too much stuff within Google that was relying on the old broken behavior and we never found the time/resources to clean that up.

I finally managed to kick off a test run within google to see what the current situation is, but I don't have high hopes that anything has changed there. I'll keep you posted on here, though.

@goderbauer
Copy link
Member

As suspected, this is failing over 200 tests within google. Some of the screenshot tests look actually broken now where more content gets cut off and new overflow warnings are produced. This would have to be investigated more closely before we can land this fix. Unfortunately (and I know this can be frustrating to hear), this is all internal code that I cannot share publicly. Furthermore, people with access to the code currently do not have the bandwidth to investigate this.

@callius
Copy link

callius commented Dec 27, 2023

Came across this as part of #140613. It would be nice to be able to add hyperlinks via RichText in the responsive web port I am working on for my apps—looking forward to a fix.

@Hixie
Copy link
Contributor

Hixie commented Mar 12, 2024

We could add a flag that controls whether or not the additional constraints are taken into account when doing intrinsic dimensions, basically turn this bug into a feature.

@goderbauer
Copy link
Member

I like the idea of turning this into a feature by having a flag to chose the behavior you want. @Albert221 @callius Would that work for your use cases? Would you be interested in implementing that? The new implementation will also have to address the infinity use case (see #72095).

@Albert221
Copy link
Contributor Author

Flag as in a SizedBox widget param?

@goderbauer
Copy link
Member

I am going to close this since as-is this will be too breaking. If somebody wants to improve this with the suggestions made above: Please open a new PR.

@Ortes
Copy link

Ortes commented Jul 18, 2024

Flag as in a SizedBox widget param?

Does this was implemented ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
framework flutter/packages/flutter repository. See also f: labels.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

SizedBox calculates intrinsic dimensions incorrectly
5 participants