Skip to content

RenderIntrinsicWidth documentation is slightly misleading. #61496

@tvolkert

Description

@tvolkert

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:

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    P1High-priority issues at the top of the work lista: layoutSystemChrome and Framework's Layout Issuesd: api docsIssues with https://api.flutter.dev/frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions