Skip to content

OverflowBox(fit: OverflowBoxFit.deferToChild): getDryLayout disagrees with layout when minWidth/maxWidth/minHeight/maxHeight override the incoming constraints #196838

Closed

Description

@wenkaifan0720

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

  1. added
    in triage
    on Nov 18, 2026
  2. puneetkukreja98 commented on Nov 18, 2026

    @puneetkukreja98
    Contributor

    @wenkaifan0720 Thanks for reporting this, routing this to team-framework.
    Console logs:

    00:06 +0: OverflowBox deferToChild: dry layout matches layout                                                                                        
    ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
    The following TestFailure was thrown running a test:
    Expected: null
      Actual: FlutterError:<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.
              The constraints used were BoxConstraints(0.0<=w<=800.0, 0.0<=h<=600.0).
              If you are not writing your own RenderBox subclass, then this is not
              your fault. Contact support:
    https://github.com/flutter/flutter/issues/new?template=02_bug.yml>
    
    When the exception was thrown, this was the stack:
    #4      main.<anonymous closure> (file:///Users/puneetkukreja/Google/test_p_app/test/test_two.dart:24:5)
    <asynchronous suspension>
    #5      testWidgets.<anonymous closure>.<anonymous closure> (package:flutter_test/src/widget_tester.dart:192:15)
    <asynchronous suspension>
    #6      TestWidgetsFlutterBinding._runTestBody (package:flutter_test/src/binding.dart:2068:5)
    <asynchronous suspension>
    <asynchronous suspension>
    (elided one frame from package:stack_trace)
    
    This was caught by the test expectation on the following line:
      file:///Users/puneetkukreja/Google/test_p_app/test/test_two.dart line 24
    The test description was:
      OverflowBox deferToChild: dry layout matches layout
    ════════════════════════════════════════════════════════════════════════════════════════════════════
    00:06 +0 -1: OverflowBox deferToChild: dry layout matches layout [E]                                                                                 
      Test failed. See exception logs above.
      The test description was: OverflowBox deferToChild: dry layout matches layout
      
    
    To run this test again: /Users/puneetkukreja/flutter-contribution/flutter/bin/cache/dart-sdk/bin/dart test /Users/puneetkukreja/Google/test_p_app/test/test_two.dart -p vm --plain-name 'OverflowBox deferToChild: dry layout matches layout'
    00:06 +0 -1: Some tests failed.                    

    flutter doctor -v:

    [✓] Flutter (Channel master, 3.51.0-1.0.pre-118, on macOS 26.4.1 25E253 darwin-arm64, locale en-US) [1,982ms]
        • Flutter version 3.51.0-1.0.pre-118 on channel master at /Users/puneetkukreja/flutter-contribution/flutter
        • Upstream repository https://github.com/puneetkukreja98/flutter
        • FLUTTER_GIT_URL = https://github.com/puneetkukreja98/flutter
        • Framework revision bd400446b7 (5 days ago), 2026-11-13 07:56:56 +0000
        • Engine revision bd400446b7
        • Dart version 3.15.0 (build 3.15.0-145.0.dev)
        • DevTools version 2.63.0-dev.0
        • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop, enable-android, enable-ios, cli-animations, enable-native-assets, enable-record-use,
          enable-swift-package-manager, omit-legacy-version-file, enable-windowing, enable-lldb-debugging, enable-uiscene-migration, enable-riscv64, enable-hcpp
    
    [✓] Android toolchain - develop for Android devices (Android SDK version 37.0.0-rc1) [3.1s]
        • Android SDK at /Users/puneetkukreja/Library/Android/sdk
        • Emulator version 37.1.11.0 (build_id 15917651) (CL:N/A)
        • Platform android-37.1, build-tools 37.0.0-rc1
        • Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.jdk/Contents/Home/bin/java
          This JDK is specified in your Flutter configuration.
          To change the current JDK, run: `flutter config --jdk-dir="path/to/jdk"`.
        • Java version Java(TM) SE Runtime Environment (build 17.0.12+8-LTS-286)
        • All Android licenses accepted.
    
    [✓] Xcode - develop for iOS and macOS (Xcode 26.6) [1,351ms]
        • Xcode at /Applications/Xcode.app/Contents/Developer
        • Build 17F113
        • CocoaPods version 1.16.2
    
    [✓] Chrome - develop for the web [8ms]
        • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
    
    [✓] Connected device (2 available) [7.4s]
        • macOS (desktop) • macos  • darwin-arm64   • macOS 26.4.1 25E253 darwin-arm64
        • Chrome (web)    • chrome • web-javascript • Google Chrome 157.0.8103.79
        ! Error: Browsing on the local area network for Puneet’s iPhone. Ensure the device is unlocked and attached with a cable or associated with the same local area network as this Mac.
          The device must be opted into Developer Mode to connect wirelessly. (code -27)
    
    [✓] Network resources [768ms]
        • All expected network resources are available.
    
    • No issues found!
    
  3. added
    a: tests
    framework
    team-framework
    a: layout
    and removed
    in triage
    on Nov 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: layouta: testsframeworkteam-framework

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions