-
Notifications
You must be signed in to change notification settings - Fork 29.3k
Description
Currently, if RenderIntrinsicWidth
is given tight constraints, it won't even ask its child for its intrinsic width - it'll just give the child the same constraints:
flutter/packages/flutter/lib/src/rendering/proxy_box.dart
Lines 641 to 646 in 77efc00
BoxConstraints childConstraints = constraints; | |
if (!childConstraints.hasTightWidth) { | |
final double width = child.getMaxIntrinsicWidth(childConstraints.maxHeight); | |
assert(width.isFinite); | |
childConstraints = childConstraints.tighten(width: _applyStep(width, _stepWidth)); | |
} |
This seems wrong, and in contradiction to the documentation on the class:
Sizes its child's width to the child's maximum intrinsic width ... This class is useful, for example, when unlimited width is available and you would like a child that would otherwise attempt to expand infinitely to instead size itself to a more reasonable width.
It seems like, much like RenderFlex
, RenderIntrinsicWidth
could honor its constraints while allowing its child to be smaller than the parent (RenderIntrinsicWidth
).
For example, consider the following Render Tree:
RenderView
│ configuration: Size(800, 600) at 1.0x (in logical pixels)
│ size: Size(800, 600)
└ RenderIntrinsicWidth
│ constraints: BoxConstraints(w=800, h=600)
│ size: Size(800, 600)
└ RenderConstrainedBox
│ constraints: BoxConstraints(w=800, h=600)
│ additionalConstraints: BoxConstraints(w=200, h=200)
│ size: Size(800, 600)
In this case, the RenderIntrinsicWidth
needs to be 800x600 because it received tight constraints by its parent RenderView
. However, it should relax those constraints that it passes to the child when it asks for the child's max intrinsic width to be:
childConstraints: BoxConstraints(0.0<=w<=800.0, h=600.0)
This would yield the following tree, which would be truer to the documented behavior of the render object:
RenderView
│ configuration: Size(800, 600) at 1.0x (in logical pixels)
│ size: Size(800, 600)
└ RenderIntrinsicWidth
│ constraints: BoxConstraints(w=800, h=600)
│ size: Size(800, 600)
└ RenderConstrainedBox
│ constraints: BoxConstraints(w=200, h=600) // because they're tightened to the child's intrinsic width
│ additionalConstraints: BoxConstraints(w=200, h=200)
│ size: Size(200, 600)
Additional information
All of the above also applies to RenderIntrinsicHeight