Skip to content

Commit 13a0d47

Browse files
authored
Convert menus to use OverlayPortal (#130534)
## Description This converts the `MenuAnchor` class to use `OverlayPortal` instead of directly using the overlay. ## Related Issues - Fixes #124830 ## Tests - No tests yet (hence it is a draft)
1 parent 1599cbe commit 13a0d47

File tree

11 files changed

+384
-289
lines changed

11 files changed

+384
-289
lines changed

examples/api/lib/material/menu_anchor/menu_anchor.2.dart

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@ import 'package:flutter/material.dart';
66

77
/// Flutter code sample for [MenuAnchor].
88
9-
// This is the type used by the menu below.
10-
enum SampleItem { itemOne, itemTwo, itemThree }
119

1210
void main() => runApp(const MenuAnchorApp());
1311

12+
// This is the type used by the menu below.
13+
enum SampleItem { itemOne, itemTwo, itemThree }
14+
1415
class MenuAnchorApp extends StatelessWidget {
1516
const MenuAnchorApp({super.key});
1617

@@ -36,7 +37,10 @@ class _MenuAnchorExampleState extends State<MenuAnchorExample> {
3637
@override
3738
Widget build(BuildContext context) {
3839
return Scaffold(
39-
appBar: AppBar(title: const Text('MenuAnchorButton')),
40+
appBar: AppBar(
41+
title: const Text('MenuAnchorButton'),
42+
backgroundColor: Theme.of(context).primaryColorLight,
43+
),
4044
body: Center(
4145
child: MenuAnchor(
4246
builder:

examples/api/test/material/menu_anchor/menu_anchor.1_test.dart

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,18 @@ void main() {
5151

5252
expect(find.text('Background Color'), findsOneWidget);
5353

54+
// Focusing the background color item with the keyboard caused the submenu
55+
// to open. Tapping it should cause it to close.
5456
await tester.tap(find.text('Background Color'));
57+
await tester.pump();
58+
await tester.pumpAndSettle();
59+
60+
expect(find.text(example.MenuEntry.colorRed.label), findsNothing);
61+
expect(find.text(example.MenuEntry.colorGreen.label), findsNothing);
62+
expect(find.text(example.MenuEntry.colorBlue.label), findsNothing);
63+
64+
await tester.tap(find.text('Background Color'));
65+
await tester.pump();
5566
await tester.pumpAndSettle();
5667

5768
expect(find.text(example.MenuEntry.colorRed.label), findsOneWidget);

0 commit comments

Comments
 (0)