Enable the context menu examples on web (#1687)

pull/1688/head
Justin McCandless 2 years ago committed by GitHub
parent b4c64cff9a
commit 7874e554b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -10,9 +10,6 @@ such as the text selection toolbar on mobile or the right click menu on desktop.
Just run `flutter run` in the same directory as this README file. Just run `flutter run` in the same directory as this README file.
Currently, most of the examples in this demo do not support web, because Flutter
uses the browser's built-in context menu instead.
## The examples ## The examples
### [Anywhere](https://github.com/flutter/samples/blob/main/experimental/context_menus/lib/anywhere_page.dart) ### [Anywhere](https://github.com/flutter/samples/blob/main/experimental/context_menus/lib/anywhere_page.dart)

@ -1,5 +1,6 @@
import 'package:flutter/foundation.dart'; import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'anywhere_page.dart'; import 'anywhere_page.dart';
import 'cascading_menu_page.dart'; import 'cascading_menu_page.dart';
@ -35,6 +36,24 @@ class _MyAppState extends State<MyApp> {
}); });
} }
@override
void initState() {
super.initState();
// On web, disable the browser's context menu everywhere so that the custom
// Flutter-rendered context menu shows.
if (kIsWeb) {
BrowserContextMenu.disableContextMenu();
}
}
@override
void dispose() {
if (kIsWeb) {
BrowserContextMenu.enableContextMenu();
}
super.dispose();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(

@ -22,7 +22,8 @@ declare -ar PROJECT_NAMES=(
"code_sharing/shared" "code_sharing/shared"
"desktop_photo_search/fluent_ui" "desktop_photo_search/fluent_ui"
"desktop_photo_search/material" "desktop_photo_search/material"
"experimental/context_menus" # TODO(DomesticMouse): uncomment on next Flutter stable increment
# "experimental/context_menus"
"experimental/federated_plugin/federated_plugin" "experimental/federated_plugin/federated_plugin"
"experimental/federated_plugin/federated_plugin/example" "experimental/federated_plugin/federated_plugin/example"
"experimental/federated_plugin/federated_plugin_macos" "experimental/federated_plugin/federated_plugin_macos"

Loading…
Cancel
Save