Disable context menu (#128365)

## Description

Changes the context menu example for `MenuAnchor` so that it uses right-click, or (on macOS and iOS only) ctrl-left-click, for the context menu. Also disables the browser context menu on web platforms.

## Tests
 - Updated test to reflect new triggers.
This commit is contained in:
Greg Spencer
2023-06-07 16:40:17 -07:00
committed by GitHub
parent 5328bd9ae0
commit 36f73cf645
2 changed files with 57 additions and 12 deletions

View File

@@ -2,6 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/gestures.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_api_samples/material/menu_anchor/menu_anchor.1.dart' as example;
@@ -18,15 +19,13 @@ void main() {
await tester.pumpWidget(const example.ContextMenuApp());
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlRight);
await tester.tapAt(const Offset(100, 200));
await tester.tapAt(const Offset(100, 200), buttons: kSecondaryButton);
await tester.pump();
expect(tester.getRect(findMenu()), equals(const Rect.fromLTRB(100.0, 200.0, 433.0, 360.0)));
// Make sure tapping in a different place causes the menu to move.
await tester.tapAt(const Offset(200, 100));
await tester.tapAt(const Offset(200, 100), buttons: kSecondaryButton);
await tester.pump();
await tester.sendKeyUpEvent(LogicalKeyboardKey.controlRight);
expect(tester.getRect(findMenu()), equals(const Rect.fromLTRB(200.0, 100.0, 533.0, 260.0)));
@@ -67,8 +66,7 @@ void main() {
);
// Open the menu so we can look for state changes reflected in the menu.
await tester.sendKeyDownEvent(LogicalKeyboardKey.controlRight);
await tester.tapAt(const Offset(100, 200));
await tester.tapAt(const Offset(100, 200), buttons: kSecondaryButton);
await tester.pump();
expect(find.text(example.MenuEntry.showMessage.label), findsOneWidget);