Repository: flutter/flutter
File: packages/flutter/test/material/menu_anchor_test.dart (Dart)

Code before:
      expect(find.byIcon(defaultIcon), findsOneWidget);

      await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
      await tester.pump();
      expect(find.byIcon(focusedIcon), findsOneWidget);

      controller.close();
      await tester.pump();

      await tester.tap(find.text(TestMenu.subMenu00.label));
      await tester.pump();
      await hoverOver(tester, find.text(TestMenu.subSubMenu110.label));
      await tester.pump();
      expect(find.byIcon(hoveredIcon), findsOneWidget);

      controller.close();
      await tester.pump();

      await tester.pumpWidget(buildMenu(icon: submenuIcon, enabled: false));
      await tester.tap(find.text(TestMenu.subMenu00.label));
      await tester.pump();
      expect(find.byIcon(disabledIcon), findsOneWidget);
    });
  });

  testWidgets('MenuAnchor.of gives nearest MenuAnchor ancestor', (WidgetTester tester) async {
    final MenuController controller = MenuController();
    await tester.pumpWidget(
      MaterialApp(
        home: Scaffold(
          body: Center(
            child: MenuAnchor(
              controller: controller,
              menuChildren: const <Widget>[MenuItemButton(child: Text('menu item'))],
              builder: (BuildContext context, MenuController controller, Widget? child) {
                return FilledButton(
                  onPressed: () {
                    if (controller.isOpen) {
                      controller.close();
                    } else {
                      controller.open();
                    }
                  },
                  child: Text(controller.isOpen ? 'close' : 'open'),
                );
              },
            ),
          ),
        ),
      ),
    );

Review comment (suggestion):
```suggestion
  testWidgets('MenuAnchor.of can return the nearest MenuController', (WidgetTester tester) async {
```

Code after:
      expect(find.byIcon(defaultIcon), findsOneWidget);

      await tester.sendKeyEvent(LogicalKeyboardKey.arrowDown);
      await tester.pump();
      expect(find.byIcon(focusedIcon), findsOneWidget);

      controller.close();
      await tester.pump();

      await tester.tap(find.text(TestMenu.subMenu00.label));
      await tester.pump();
      await hoverOver(tester, find.text(TestMenu.subSubMenu110.label));
      await tester.pump();
      expect(find.byIcon(hoveredIcon), findsOneWidget);

      controller.close();
      await tester.pump();

      await tester.pumpWidget(buildMenu(icon: submenuIcon, enabled: false));
      await tester.tap(find.text(TestMenu.subMenu00.label));
      await tester.pump();
      expect(find.byIcon(disabledIcon), findsOneWidget);
    });
  });
}

List<Widget> createTestMenus({
  void Function(TestMenu)? onPressed,
  void Function(TestMenu)? onOpen,
  void Function(TestMenu)? onClose,
  Map<TestMenu, MenuSerializableShortcut> shortcuts = const <TestMenu, MenuSerializableShortcut>{},
  bool includeExtraGroups = false,
  bool accelerators = false,
}) {
  Widget submenuButton(TestMenu menu, {required List<Widget> menuChildren}) {
    return SubmenuButton(
      onOpen: onOpen != null ? () => onOpen(menu) : null,
      onClose: onClose != null ? () => onClose(menu) : null,
      menuChildren: menuChildren,
      child: accelerators ? MenuAcceleratorLabel(menu.acceleratorLabel) : Text(menu.label),
    );
  }

  Widget menuItemButton(
    TestMenu menu, {
    bool enabled = true,
    Widget? leadingIcon,
    Widget? trailingIcon,
    Key? key,
  }) {
    return MenuItemButton(