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.
  • 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,
)

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.