ContextMenuController class

Builds and manages a context menu at a given location.

There can only ever be one context menu shown at a given time in the entire app. Calling show on one instance of this class will hide any other shown instances.

This example shows how to use a GestureDetector to show a context menu anywhere in a widget subtree that receives a right click or long press.

To create a local project with this code sample, run:
flutter create --sample=widgets.ContextMenuController.1 mysample

See also:

  • BrowserContextMenu, which allows the browser's context menu on web to be disabled and Flutter-rendered context menus to appear.


ContextMenuController({VoidCallback? onRemove})
Creates a context menu that can be shown with show.


hashCode int
The hash code for this object.
no setterinherited
isShown bool
True if and only if this menu is currently being shown.
no setter
onRemove VoidCallback?
Called when this menu is removed.
runtimeType Type
A representation of the runtime type of the object.
no setterinherited


markNeedsBuild() → void
Cause the underlying OverlayEntry to rebuild during the next pipeline flush.
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
remove() → void
Remove this menu from the UI.
show({required BuildContext context, required WidgetBuilder contextMenuBuilder, Widget? debugRequiredFor}) → void
Shows the given context menu.
toString() String
A string representation of this object.


operator ==(Object other) bool
The equality operator.

Static Methods

removeAny() → void
Remove the currently shown context menu from the UI.