flutter / flutter/flutter

Allow `RenderObjects` to report to their parent that they don't fit constraints

Open
#183,443 3 comments 0 reactions 0 assignees View on GitHub
P2 team-framework triaged-framework
Dominant language
Dart
Stars
179k
Forks
31.1k
PR merge metrics
PR metrics pending

Description

### Use case

I want to build a transition that shrinks its child until it cannot shrink further without overflowing.

For this I am trying to write a `RenderBox` that basically does the following:

- compute desired height based on animation value
- lay out child with that height
- check if the child was able to fit <- this is what seems to be impossible
- if desired height is smaller than what the child can shrink to, translate instead.

The desired effect is basically what you can see here, but without the overflows:

https://github.com/user-attachments/assets/2c154a01-10d4-4a87-a2eb-d53f139cdd77

The key problem seems to be that the child is obviously contractually obligated to fit the parent constraints, but some children internally decide to complain when they actually didn't want to.

#### Why not intrinsic height?
One mechanism for this would be querying the child's intrinsic height. However if the child is a `Column([Expanded(ListView), SizedBox(height: 64)]);` that fails because scrollables will refuse to report intrinsics. Even though the whole column can still overflow when shrunk past 64 height.

### Proposal

I would like those children to be able to communicate to the parent that they didn't want to meet constraints before deciding to complain.

I might not see the full picture here, because this seems like too great an omission to not have a good reason. But I feel like this would not need an extra pass for layout, or have any other serious performance implications. I also couldn't believe that I could not find an issue for this, so apologies if this is a duplicate.

All we would need is something like an additional `desiredSize` field that the child can choose to set during layout and the parent can read just like `child.size`. There is probably a better API design.

In my use case I could then check if the child would have wanted to be larger, re-layout the child and size myself accordingly.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.