Repository navigation
Description
Steps to reproduce
Run this widget test (flutter test). It turns on Flutter's own debugCheckIntrinsicSizes check, which every
framework test already runs with (packages/flutter/test/flutter_test_config.dart):
import 'package:flutter/rendering.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('OverflowBox deferToChild: dry layout matches layout', (WidgetTester tester) async {
debugCheckIntrinsicSizes = true;
await tester.pumpWidget(
const Directionality(
textDirection: TextDirection.ltr,
child: Align(
alignment: Alignment.topLeft,
child: OverflowBox(
fit: OverflowBoxFit.deferToChild,
minWidth: 200,
child: SizedBox(width: 50, height: 50),
),
),
),
);
debugCheckIntrinsicSizes = false;
expect(tester.takeException(), isNull);
});
}Expected results
The test passes: OverflowBox lays itself out at 200x50, and getDryLayout gives the same size, as the
RenderBox.computeDryLayout docs require ("The size returned by this method must match the [size] that the
[RenderBox] will compute for itself in [performLayout]").
Actual results
Flutter's own check throws:
The size given to the RenderConstrainedOverflowBox class differs from the size computed by computeDryLayout.
The size computed in performLayout is Size(200.0, 50.0), which is different from Size(50.0, 50.0), which was computed by computeDryLayout.
...
If you are not writing your own RenderBox subclass, then this is not your fault.
The same widget with the default fit: OverflowBoxFit.max passes.
Where it shows up
We hit this in generated layouts before we found the cause. A title with maxWidth: 451 that wraps to two lines sat
under an OverflowBox(fit: OverflowBoxFit.deferToChild) in a grid column 954 wide, and the grid asked its children
for their dry layout to size its rows. The OverflowBox answered the child's dry size under the column's
constraints (one line, 44 tall) instead of under its own (two lines, 88 tall). So the row came out a line short, and
the next paragraph was painted over the title's second line. We work around it today by overriding
computeDryLayout in a subclass, the same way as the fix below.
Cause
RenderConstrainedOverflowBox.computeDryLayout asks the child for its dry size under the incoming constraints:
OverflowBoxFit.deferToChild => child?.getDryLayout(constraints) ?? constraints.smallest,performLayout lays the child out under the inner constraints and then constrains the result to the incoming ones:
child!.layout(_getInnerConstraints(constraints), parentUsesSize: true);
...
case OverflowBoxFit.deferToChild:
size = constraints.constrain(child!.size);computeDryBaseline in the same class already uses _getInnerConstraints(constraints) for the child, but it gets the
box's own size from getDryLayout(constraints), so dry baselines are off as well. The code dates from #129095,
which added deferToChild; its tests don't call getDryLayout.
Reproduces on Flutter 3.50.0 (current stable), 3.47.8 and 3.38.5. The line is unchanged on master as of today.
Suggested fix
OverflowBoxFit.deferToChild => constraints.constrain(
child?.getDryLayout(_getInnerConstraints(constraints)) ?? constraints.smallest,
),This mirrors performLayout. With this change, a new test in test/widgets/overflow_box_test.dart (four cases:
min above the child, max below the incoming max, a tight incoming width, a child larger than the incoming max) passes
and fails without it. On 3.47.8, the whole packages/flutter suite (916 files, 20,884 tests) gives the same failures
with and without the change: 70 golden pixel mismatches local to my machine, none new. dart analyze and dart format are
clean.
Happy to send the PR.
Flutter doctor
Flutter 3.50.0 (stable, framework revision ab29120), macOS. Also reproduced on 3.47.8 and 3.38.5.
Activity
puneetkukreja98 commentedon Nov 18, 2026
@wenkaifan0720 Thanks for reporting this, routing this to team-framework.
Console logs:
flutter doctor -v:
Fix OverflowBox dry layout when deferToChild overrides the constraints (