s_context_menu/src/s_context_menu library

SContextMenu – Advanced contextual actions widget

Features:

  • Right-click (desktop) or long-press (touch) to open.
  • Animated fade + scale panel and arrow.
  • Automatic smart positioning with arrow corner selection.
  • Accessible: optional screen reader announcement & semantic labels.
  • Overflow handling (scrolls when too tall).
  • Keyboard listener: Captures key presses while menu is active (prints to console).
  • Theming via SContextMenuTheme (panel colors, blur, radii, arrow shape, durations, blur, shadows).
  • Re-entrant safe (closing old before opening new) with show throttling to prevent accidental spam.
  • Optional multi-open mode (allowMultipleMenus: true) to keep several menus visible at once.
  • Lifecycle callbacks: onOpened, onClosed.
  • Outside tap callback: onTapOutsideMenu with this menu's TapRegion groupId.
  • Programmatic control:

Basic usage:

SContextMenu(
  buttons: [
    SContextMenuItem(label: 'Edit', icon: Icons.edit, onPressed: onEdit),
    SContextMenuItem(label: 'Delete', icon: Icons.delete, destructive: true, onPressed: onDelete),
  ],
  child: YourTargetWidget(),
);

Enable multiple concurrent menus:

SContextMenu(
  allowMultipleMenus: true,
  buttons: [...],
  child: widgetA,
);
SContextMenu(
  allowMultipleMenus: true,
  buttons: [...],
  child: widgetB,
);
// Later you can close them all:
SContextMenu.closeAllOpenMenus();

Theming:

SContextMenu(
  theme: const SContextMenuTheme(panelBorderRadius: 12, panelBlurSigma: 30),
  buttons: [...],
  child: widget,
)

Arrow visibility:

// Per-menu override
SContextMenu(showArrow: true, buttons: [...], child: widget)

// Or theme-level default
SContextMenu(theme: SContextMenuTheme.desktop, buttons: [...], child: widget)

Programmatic close (e.g. before route change):

SContextMenu.closeOpenMenu();

Notes:

  • followAnchor: true keeps menu tethered to the child (respects size/metric changes).
  • Provide an empty buttons list to fall back to a default placeholder button.
  • Long-press duration fixed at 600ms (adjust easily in code if required).
  • Keyboard events are only captured while the menu is visible and focused.
  • Press ESC to close the menu via keyboard interaction.

Classes

ArrowConfig
Arrow styling configuration for SContextMenuTheme.
ArrowGeometry
Resolved geometric points used to paint and clip a context-menu arrow.
SContextMenu
SContextMenuControllers
SContextMenuItem
Immutable model representing one action row in SContextMenu.
SContextMenuTheme
Theme and styling configuration for SContextMenu.

Enums

ArrowCorner
Corner anchor used to place the menu arrow pointer.
ArrowShape
Arrow visual style used by context menu pointer rendering.