Skip to content

[widgets/raw_menu_anchor.dart] onClose should be called by descendant menus before parent #182355

Description

@davidhicks980

Steps to reproduce

  1. Run example
  2. Open until you reach "Close Root Menu"
  3. Tap "Close Root Menu"
  4. Read console

Expected results

Should print

> onClose Submenu
> onClose Root

Actual results

Prints

> onClose Root

Code sample

Code sample
class App extends StatefulWidget {
  const App({super.key});

  @override
  State<App> createState() => _AppState();
}

class _AppState extends State<App> {
  @override
  Widget build(BuildContext context) {
    return const CupertinoApp(home: CupertinoPageScaffold(child: Bug()));
  }
}

class Bug extends StatelessWidget {
  const Bug({super.key});

  @override
  Widget build(BuildContext context) {
    return Center(
      child: RawMenuAnchor(
        controller: MenuController(),
        builder: (context, controller, child) {
          return CupertinoButton.filled(onPressed: controller.open, child: const Text('Open'));
        },
        onClose: () {
          print('onClose Root');
        },
        overlayBuilder: (context, info) {
          return Positioned(
            left: info.anchorRect.left,
            top: info.anchorRect.bottom + 4,
            child: TapRegion(
              groupId: info.tapRegionGroupId,
              child: RawMenuAnchor(
                controller: MenuController(),
                onClose: () {
                  print('onClose Submenu');
                },
                onCloseRequested: (hideMenu) {},
                builder: (context, controller, child) {
                  return CupertinoButton.filled(
                    onPressed: controller.open,
                    child: const Text('Open'),
                  );
                },
                overlayBuilder: (context, info) {
                  return Positioned(
                    left: info.anchorRect.left,
                    top: info.anchorRect.bottom + 4,
                    child: TapRegion(
                      groupId: info.tapRegionGroupId,
                      child: CupertinoButton.filled(
                        onPressed: () {
                          Actions.invoke(context, const DismissIntent());
                        },
                        child: const Text('Close Root Menu'),
                      ),
                    ),
                  );
                },
              ),
            ),
          );
        },
      ),
    );
  }
}

Screenshots or Video

Screenshots / Video demonstration

N/a

Logs

Logs

No relevant logs

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.42.0-1.0.pre-18, on macOS 15.5 24F74 darwin-arm64, locale en-US) [1,297ms]
    • Flutter version 3.42.0-1.0.pre-18 on channel master at /Users/davidhicks/fvm/versions/master
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 73a7978d56 (4 days ago), 2026-02-09 00:59:49 -0500
    • Engine revision 73a7978d56
    • Dart version 3.12.0 (build 3.12.0-127.0.dev)
    • DevTools version 2.54.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, enable-uiscene-migration, enable-riscv64

[✓] Android toolchain - develop for Android devices (Android SDK version 36.1.0) [2.6s]
    • Android SDK at /Users/davidhicks/Library/Android/sdk
    • Emulator version 36.3.10.0 (build_id 14472402) (CL:N/A)
    • Platform android-36.1, build-tools 36.1.0
    • ANDROID_HOME = /Users/davidhicks/Library/Android/sdk
    • Java binary at: /Users/davidhicks/Library/Java/JavaVirtualMachines/jbr-17.0.14/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 OpenJDK Runtime Environment JBR-17.0.14+1-1367.22-nomod (build 17.0.14+1-b1367.22)
    • All Android licenses accepted.

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

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

[✓] Connected device (2 available) [6.1s]
    • macOS (desktop) • macos  • darwin-arm64   • macOS 15.5 24F74 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 145.0.7632.68
    ! 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 [261ms]
    • All expected network resources are available.

• No issues found!

Metadata

Metadata

Assignees

Labels

P2Important issues not at the top of the work listframeworkflutter/packages/flutter repository. See also f: labels.team-frameworkOwned by Framework teamtriaged-frameworkTriaged by Framework team

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions