Skip to content

[material/menu_anchor.dart] Reserved padding doesn't update on padding changes. #176456

Closed

Description

@davidhicks980

Steps to reproduce

Found by looking at the MenuAnchor source:

  @override
  bool shouldRelayout(_MenuLayout oldDelegate) {
    return anchorRect != oldDelegate.anchorRect ||
        textDirection != oldDelegate.textDirection ||
        alignment != oldDelegate.alignment ||
        alignmentOffset != oldDelegate.alignmentOffset ||
        menuPosition != oldDelegate.menuPosition ||
        menuPadding != oldDelegate.menuPadding ||
        orientation != oldDelegate.orientation ||
        parentOrientation != oldDelegate.parentOrientation ||
        // Need to check for reserved padding equality
        // reservedPadding != oldDelegate.reservedPadding || 
        !setEquals(avoidBounds, oldDelegate.avoidBounds);
  }

I couldn't find a good way to replicate other than via a test. So, run the attached test and it should fail. I'll submit a fix ASAP.

Expected results

Test passes

Actual results

Test fails

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';

void main() {
  testWidgets('Layout updates when reserved padding changes', (
    WidgetTester tester,
  ) async {
    MenuController controller = MenuController();
    const EdgeInsetsGeometry reservedPadding = EdgeInsets.symmetric(
      horizontal: 13.0,
    );

    await tester.pumpWidget(
      MaterialApp(
        home: MenuAnchor(
          controller: controller,
          menuChildren: const <Widget>[SizedBox(width: 800, height: 24)],
        ),
      ),
    );

    controller.open(position: Offset.zero);
    await tester.pump();

    await tester.pumpWidget(
      MaterialApp(
        home: MenuAnchor(
          controller: controller,
          reservedPadding: reservedPadding,
          menuChildren: const <Widget>[SizedBox(width: 800, height: 24)],
        ),
      ),
    );

    expect(
      tester
          .getRect(
            find.byWidgetPredicate(
              (Widget widget) => widget.runtimeType.toString() == '_MenuPanel',
            ),
          )
          .width,
      800.0 - reservedPadding.horizontal,
    );
  });
}

Screenshots or Video

Screenshots / Video demonstration

N/a

Logs

Logs
N/a

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.37.0-1.0.pre-397, on macOS 15.5 24F74 darwin-arm64, locale en-US)
    [1,381ms]
    • Flutter version 3.37.0-1.0.pre-397 on channel master at /Users/davidhicks/fvm/versions/master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 018897e3f1 (4 hours ago), 2025-10-03 03:22:28 -0400
    • Engine revision 018897e3f1
    • Dart version 3.10.0 (build 3.10.0-275.0.dev)
    • DevTools version 2.50.0
    • Feature flags: enable-web, enable-linux-desktop, enable-macos-desktop, enable-windows-desktop,
      enable-android, enable-ios, cli-animations, enable-native-assets, omit-legacy-version-file,
      enable-lldb-debugging

[!] Android toolchain - develop for Android devices (Android SDK version 35.0.0) [1,897ms]
    • Android SDK at /Users/davidhicks/Library/Android/sdk
    • Emulator version 35.4.9.0 (build_id 13025442) (CL:N/A)
    • Platform android-36, build-tools 35.0.0
    • ANDROID_HOME = /Users/davidhicks/Library/Android/sdk
    • Java binary at: /Library/Java/JavaVirtualMachines/jdk-17.0.2.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.2+8-LTS-86)
    ! Some Android licenses not accepted. To resolve this, run: flutter doctor --android-licenses

[✓] Xcode - develop for iOS and macOS (Xcode 16.4) [1,498ms]
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16F6
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web [12ms]
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Connected device (2 available) [6.4s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 140.0.7339.214
    ! Error: Browsing on the local area network for David’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 [317ms]
    • All expected network resources are available.

! Doctor found issues in 1 category.

Activity

  1. tirth-patel-nc commented on Oct 3, 2025

    @tirth-patel-nc
    Member

    Thanks for the report & a potential fix. Seeing the same behaviour with latest master SDK version. I've updated the code sample to include imports and the missing parts. Can't test on 3.35.5 since resolvePadding throws a syntax error, I believe it was introduced in later versions.

    master : 3.37.0-1.0.pre-395
    
    Test Failure Log
    ══╡ EXCEPTION CAUGHT BY FLUTTER TEST FRAMEWORK ╞════════════════════════════════════════════════════
    The following TestFailure was thrown running a test:
    Expected: <774.0>
      Actual: <784.0>
    
    When the exception was thrown, this was the stack:
    #4      main.<anonymous closure> (file:///Users/tirthpatel/oc3/test/widget_test.dart:44: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:1059: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/tirthpatel/oc3/test/widget_test.dart line 44
    The test description was:
      Layout updates when reserved padding changes
    ════════════════════════════════════════════════════════════════════════════════════════════════════
  2. added
    a: tests"flutter test", flutter_test, or one of our tests
    has reproducible stepsThe issue has been confirmed reproducible and is ready to work on
    frameworkflutter/packages/flutter repository. See also f: labels.
    p: material_uimaterial_ui package in flutter/packages
    team-designOwned by Design Languages team
    and removed
    in triagePresently being triaged by the triage team
    on Oct 3, 2025
  3. added
    r: fixedIssue is closed as already fixed in a newer version
    on Oct 4, 2025
  4. github-actions commented on Oct 18, 2025

    @github-actions

    This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.

  5. locked as resolved and limited conversation to collaborators on Oct 18, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

a: tests"flutter test", flutter_test, or one of our testsfound in release: 3.37Found to occur in 3.37frameworkflutter/packages/flutter repository. See also f: labels.has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: material_uimaterial_ui package in flutter/packagesr: fixedIssue is closed as already fixed in a newer versionteam-designOwned by Design Languages team

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions