CupertinoContextMenu class

A full-screen modal route that opens when the child is long-pressed.

When open, the CupertinoContextMenu shows the child in a large full-screen Overlay with a list of buttons specified by actions. The child/preview is placed in an Expanded widget so that it will grow to fill the Overlay if its size is unconstrained.

When closed, the CupertinoContextMenu displays the child as if the CupertinoContextMenu were not there. Sizing and positioning is unaffected. The menu can be closed like other PopupRoutes, such as by tapping the background or by calling Navigator.pop(context). Unlike PopupRoute, it can also be closed by swiping downwards.

This sample shows a very simple CupertinoContextMenu for the Flutter logo. Long press on it to open.
link

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

This sample shows a similar CupertinoContextMenu, this time using builder to add a border radius to the widget.
link

To create a local project with this code sample, run:
flutter create --sample=cupertino.CupertinoContextMenu.2 mysample

See also:

Inheritance

Constructors

CupertinoContextMenu({Key? key, required List<Widget> actions, required Widget child, bool enableHapticFeedback = false})
Create a context menu.
CupertinoContextMenu.builder({Key? key, required List<Widget> actions, required CupertinoContextMenuBuilder builder, bool enableHapticFeedback = false})
Creates a context menu with a custom builder controlling the widget.

Properties

actions List<Widget>
The actions that are shown in the menu.
final
builder CupertinoContextMenuBuilder
A function that returns a widget to be used alternatively from child.
final
child Widget?
The widget that can be "opened" with the CupertinoContextMenu.
final
enableHapticFeedback bool
If true, clicking on the CupertinoContextMenuActions will produce haptic feedback.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
runtimeType Type
A representation of the runtime type of the object.
no setterinherited

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() State<CupertinoContextMenu>
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug, int wrapWidth = 65}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

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

Static Properties

animationOpensAt double
The point at which the CupertinoContextMenu begins to animate into the open position.
final

Constants

kBackgroundColor → const Color
The background color of a CupertinoContextMenuAction and a CupertinoContextMenu sheet.
kEndBoxShadow → const List<BoxShadow>
Exposes the final box shadow of the opening animation of the child widget to match the default behavior of the native iOS widget. This value was eyeballed from the iOS simulator running iOS 16.0.
kOpenBorderRadius → const double
Exposes the default border radius for matching iOS 16.0 behavior. This value was eyeballed from the iOS simulator running iOS 16.0.