showMenu method

Future<void> showMenu({
  1. Offset? globalPosition,
})

Opens the menu at globalPosition, or at the centre of the child when null. Does nothing while the menu is already open.

Implementation

Future<void> showMenu({Offset? globalPosition}) async {
  if (_showing || !widget.enabled || widget.items.isEmpty) return;
  final position = globalPosition ?? _centre();
  if (position == null) return;
  _showing = true;
  try {
    final path = await showNativeContextMenu(
      context,
      items: widget.items,
      globalPosition: position,
    );
    if (path != null && path.isNotEmpty && mounted) {
      widget.onSelected(List<int>.unmodifiable(path));
    }
  } finally {
    _showing = false;
  }
}