GlassContextMenu class
A liquid glass context menu following Apple iOS 26/27 and SwiftUI .contextMenu() design.
When long-pressed or secondary-tapped (right-clicked on desktop/web), the wrapped child lifts above a defocused liquid glass backdrop with realistic elevation shadow, while an adjacent liquid glass action platter springs open with snappy spring physics.
Features
- Touch-and-Hold Surface Lift: When pressed and held, the row lifts off the page (about 1.036×) with a broad soft drop shadow, keeping its own corner shape.
- Row-to-Preview Morph: On commit the lifted row cross-dissolves and morphs into the centred preview card in ~190ms while the page dims, and morphs back into the row on dismiss.
- Haptic Surface Lift: Fires
HapticFeedback.mediumImpact()as the menu commits. - Native Backdrop: A plain dimming scrim (no blur by default), matching iOS.
- Elevated Specular Platter: The action list renders in a rounded superellipse liquid glass container with specular highlights.
- Smart Positioning: Automatically opens below or above the target based on available screen space and clamps safely within screen edges.
- Continuous Glide-to-Select: Dragging from the long-press directly across menu items highlights the hovered action with haptic ticks; releasing selects the action.
- Custom Preview Support: Supply previewBuilder to render custom content when lifted.
- Secondary Tap Parity: Right-click on desktop/macOS opens the menu immediately.
Usage
GlassContextMenu(
actions: [
GlassContextMenuAction(
icon: const Icon(CupertinoIcons.share),
child: const Text('Share Contact'),
onPressed: () => shareContact(),
),
GlassContextMenuAction(
icon: const Icon(CupertinoIcons.delete),
isDestructive: true,
child: const Text('Delete'),
onPressed: () => deleteContact(),
),
],
child: ContactCard(contact: contact),
)
- Inheritance
-
- Object
- DiagnosticableTree
- Widget
- StatefulWidget
- GlassContextMenu
- Available extensions
Constructors
-
GlassContextMenu({Key? key, required Widget child, required List<
Widget> actions, WidgetBuilder? previewBuilder, bool enabled = true, bool enableHaptics = true, double borderRadius = 32.0, double? previewBorderRadius, double rowBorderRadius = 16.0, BorderRadius? rowCorners, Color? originSlotColor, Color? backgroundColor, LiquidGlassSettings? settings, GlassQuality? quality, double backdropBlur = 0.0, Color? barrierColor, VoidCallback? onOpened, VoidCallback? onDismissed, Duration longPressDuration = const Duration(milliseconds: 700)}) -
Creates a GlassContextMenu.
const
Properties
-
actions
→ List<
Widget> -
The list of actions displayed in the liquid glass action platter.
final
- backdropBlur → double
-
Amount of gaussian blur applied to the backdrop when opened.
final
- backgroundColor → Color?
-
Optional background color of the row when lifted during touch-and-hold.
Defaults to secondary system grouped background color (solid white in light mode).
final
- barrierColor → Color?
-
Dimming barrier color applied behind the lifted target and platter.
final
- borderRadius → double
-
Border radius of the action menu platter (defaults to 32.0, matching the
continuous corners of iOS 26 context menus).
final
- child → Widget
-
The widget that triggers the context menu.
final
- enabled → bool
-
Whether context menu interaction is enabled.
final
- enableHaptics → bool
-
Whether to trigger haptic feedback on touch-down, lift, and action selection.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- key → Key?
-
Controls how one widget replaces another widget in the tree.
finalinherited
- longPressDuration → Duration
-
The duration of the touch-and-hold gesture required to trigger the context menu.
final
-
Width of the action menu platter (defaults to 250.0).
final
- onDismissed → VoidCallback?
-
Optional callback invoked when the context menu is dismissed.
final
- onOpened → VoidCallback?
-
Optional callback invoked when the context menu is opened.
final
- originSlotColor → Color?
-
Colour revealed in the row's slot while the row is lifted out of the page.
final
- previewBorderRadius → double?
-
Border radius of the preview card when opened. Defaults to 34.0 when
previewBuilder is supplied, or rowBorderRadius otherwise.
final
- previewBuilder → WidgetBuilder?
-
Optional builder for a custom preview widget displayed when lifted.
If null, child is displayed in the lifted preview.
final
- quality → GlassQuality?
-
Glass quality tier for rendering the action platter.
final
- rowBorderRadius → double
-
Border radius of the target row at rest and during touch-and-hold lift.
Defaults to 16.0 pt matching iOS grouped section row corners.
final
- rowCorners → BorderRadius?
-
Per-corner radii of the target row, overriding rowBorderRadius.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- settings → LiquidGlassSettings?
-
Custom liquid glass shader settings for the action platter.
final
Methods
-
createElement(
) → StatefulElement -
Creates a StatefulElement to manage this widget's location in the tree.
inherited
-
createState(
) → State< GlassContextMenu> -
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
-
glassContextMenu(
{Key? key, required List< Widget> actions, WidgetBuilder? previewBuilder, bool enabled = true, bool enableHaptics = true, double borderRadius = 32.0, double? previewBorderRadius, double rowBorderRadius = 16.0, BorderRadius? rowCorners, Color? originSlotColor, Color? backgroundColor, LiquidGlassSettings? settings, GlassQuality? quality, double backdropBlur = 0.0, Color? barrierColor, VoidCallback? onOpened, VoidCallback? onDismissed, Duration longPressDuration = const Duration(milliseconds: 700)}) → Widget -
Available on Widget, provided by the GlassContextMenuExtension extension
Wraps this widget in a GlassContextMenu displayingactionson long-press or right-click. -
glassFullScreenCover(
{required bool isPresented, VoidCallback? onDismiss, required WidgetBuilder content, bool enableSwipeToDismiss = true, double dismissThreshold = 140.0, LiquidGlassSettings? settings, GlassQuality? quality}) → Widget -
Available on Widget, provided by the GlassFullScreenCoverExtension extension
Presents a full-viewport modal cover wheneverisPresentedis true. -
Available on Widget, provided by the GlassNavigationTitleExtension extension
Annotates this widget with a navigation title that drives enclosing or descendant GlassAppBar / GlassAppBar.pinned bars (when their explicittitleis null) as well as header accessibility semantics. -
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