showMenu<T> function

Future<T?> showMenu<T>({
  1. required BuildContext context,
  2. required List<ContextMenuEntry<T>> items,
  3. required Rect position,
  4. double? width,
  5. String? semanticLabel,
  6. String? barrierLabel,
  7. T? initialValue,
  8. ContextMenuThemeData? contextMenuThemeData,
})

Shows a menu given a relative position for the target.

Implementation

Future<T?> showMenu<T>({
  required BuildContext context,
  required List<ContextMenuEntry<T>> items,
  required Rect position,
  double? width,
  String? semanticLabel,
  String? barrierLabel,
  T? initialValue,
  ContextMenuThemeData? contextMenuThemeData,
}) {
  assert(items.isNotEmpty);

  final controller = _ContextController<T>._(
    value: initialValue,
    width: width,
    items: items,
    position: position,
    contextMenuThemeData: contextMenuThemeData,
  );

  return Navigator.of(context, rootNavigator: true).push<T>(
    _ContextMenuRoute(
      pageBuilder: (context, animation, secondaryAnimation) => _ContextScope<T>(
        controller,
        child: CustomSingleChildLayout(
          delegate: ContextMenuLayoutDelegate(position),
          child: SizedBox(
            width: width,
            child: GestureDetector(
              behavior: HitTestBehavior.deferToChild,
              onTap: () {},
              child: contextMenuThemeData != null
                  ? ContextMenuTheme(
                      data: contextMenuThemeData,
                      child: _ContextMenu<T>(semanticLabel: semanticLabel),
                    )
                  : _ContextMenu<T>(semanticLabel: semanticLabel),
            ),
          ),
        ),
      ),
    ),
  );

  // Overlay.of(context, rootOverlay: true).insert(controller._overlayEntry);

  // return controller._completer.future;
}