Skip to content
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

Support intrinsic dimensions (ditch LayoutBuilder) #77

Open
creativecreatorormaybenot opened this issue Dec 14, 2020 · 4 comments
Open
Labels
enhancement New feature or request

Comments

@creativecreatorormaybenot

The problem

So, AutoSizeText does not work using IntrinsicWidth or IntrinsicHeight because:

LayoutBuilder does not support returning intrinsic dimensions.

You might say: just do not use either of these widgets, however, I believe that that is a naive approach. The reason for this is that intrinsic sizing is an integral part of the Flutter framework. It can be used anywhere.

Example

We have a custom table widget. And because tables are intricate things, they will rely on intrisic sizes. We do not use IntrinsicWidth or IntrinsicHeight - we simply use the RenderBox contract:

There are four methods to implement for intrinsic sizing, to compute the minimum and maximum intrinsic width and height of the box. The documentation for these methods discusses the protocol in detail: computeMinIntrinsicWidth, computeMaxIntrinsicWidth, computeMinIntrinsicHeight, computeMaxIntrinsicHeight.

Consequences

If you have any AutoSizeText widget in a widget that makes use of the intrinsic sizing contract, AutoSizeText will completely break that widget because it uses LayoutBuilder.

Solution

Here is a solution that could work (have not thought it through yet):

We should probably rewrite AutoSizeText to ditch LayoutBuilder.
We could do this by writing our own RenderBox (leaf render object) subclass. This would allow us to fulfill the intrinsic sizing contract and also properly perform the layout.
We would be able to directly access the text painter instead of proxying through the layout builder.

Related issues

@creativecreatorormaybenot creativecreatorormaybenot added the enhancement New feature or request label Dec 14, 2020
@creativecreatorormaybenot creativecreatorormaybenot changed the title Support intrinsic dimensions Support intrinsic dimensions (ditch LayoutBuilder) Dec 14, 2020
@luqmanhakem
Copy link

Hello @leisim, is there any future plan for this enhancement or hack turnaround solution?

Much thanks!

@simc
Copy link
Owner

simc commented Nov 2, 2021

@creativecreatorormaybenot @luqmanhakem This seems like a problem we should fix. I probably won't have time to implement it in the near future but I'll review any PR proposal as quickly as possible.

@ciriousjoker
Copy link

This also means AutoSize can't be used inside SliverFillRemaining :(

@cyberpwnn
Copy link

Using a layoutbuilder to find the width i can "Take" to auto size button actions on the app bar and overflow the rest to a ... more menu.

I cant do this because there is an intrinsic height sizing the app bar in my ui framework. I dont even care about the height constraint in my layout builder, even though I agree with the issue, my situation is just dumb, i should be able to use intrinsic height and get the width constraint at later.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants