Convert menus to use OverlayPortal (#130534)

## Description

This converts the `MenuAnchor` class to use `OverlayPortal` instead of directly using the overlay.

## Related Issues
 - Fixes https://github.com/flutter/flutter/issues/124830

## Tests
 - No tests yet (hence it is a draft)
This commit is contained in:
Greg Spencer
2023-10-18 13:13:08 -07:00
committed by GitHub
parent 1599cbebc3
commit 13a0d475f5
11 changed files with 384 additions and 289 deletions

View File

@@ -6,11 +6,12 @@ import 'package:flutter/material.dart';
/// Flutter code sample for [MenuAnchor].
// This is the type used by the menu below.
enum SampleItem { itemOne, itemTwo, itemThree }
void main() => runApp(const MenuAnchorApp());
// This is the type used by the menu below.
enum SampleItem { itemOne, itemTwo, itemThree }
class MenuAnchorApp extends StatelessWidget {
const MenuAnchorApp({super.key});
@@ -36,7 +37,10 @@ class _MenuAnchorExampleState extends State<MenuAnchorExample> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('MenuAnchorButton')),
appBar: AppBar(
title: const Text('MenuAnchorButton'),
backgroundColor: Theme.of(context).primaryColorLight,
),
body: Center(
child: MenuAnchor(
builder:

View File

@@ -51,7 +51,18 @@ void main() {
expect(find.text('Background Color'), findsOneWidget);
// Focusing the background color item with the keyboard caused the submenu
// to open. Tapping it should cause it to close.
await tester.tap(find.text('Background Color'));
await tester.pump();
await tester.pumpAndSettle();
expect(find.text(example.MenuEntry.colorRed.label), findsNothing);
expect(find.text(example.MenuEntry.colorGreen.label), findsNothing);
expect(find.text(example.MenuEntry.colorBlue.label), findsNothing);
await tester.tap(find.text('Background Color'));
await tester.pump();
await tester.pumpAndSettle();
expect(find.text(example.MenuEntry.colorRed.label), findsOneWidget);