showContextMenu static method

Future<int?> showContextMenu(
  1. BuildContext context, {
  2. required GlobalKey<State<StatefulWidget>> anchorKey,
  3. required List<Phase> phases,
})

Implementation

static Future<int?> showContextMenu(
  BuildContext context, {
  required GlobalKey anchorKey,
  required List<Phase> phases,
}) async {
  final renderBox =
      anchorKey.currentContext?.findRenderObject() as RenderBox?;
  if (renderBox == null) return null;

  final offset = renderBox.localToGlobal(Offset.zero);
  final size = renderBox.size;

  return showMenu<int>(
    context: context,
    position: RelativeRect.fromLTRB(
      offset.dx,
      offset.dy + size.height,
      offset.dx + size.width,
      offset.dy,
    ),
    items: List.generate(phases.length, (index) {
      final phase = phases[index];
      return PopupMenuItem<int>(
        value: index,
        child: _MiniPhaseTile(phase: phase),
      );
    }),
  );
}