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:
@@ -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:
|
||||
|
||||
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user