showPopover static method

void showPopover({
  1. required GlobalKey<State<StatefulWidget>> key,
  2. required BuildContext context,
  3. required GlobalKey<State<StatefulWidget>> anchorKey,
  4. CDKDialogPopoverType type = CDKDialogPopoverType.center,
  5. bool isAnimated = false,
  6. bool isTranslucent = false,
  7. Function? onHide,
  8. required Widget child,
})

Implementation

static void showPopover({
  required GlobalKey key,
  required BuildContext context,
  required GlobalKey anchorKey,
  CDKDialogPopoverType type = CDKDialogPopoverType.center,
  bool isAnimated = false,
  bool isTranslucent = false,
  Function? onHide,
  required Widget child,
}) {
  if (_activePopoverKeys.containsKey(anchorKey)) {
    moveDraggableToTop(context, anchorKey);
    return;
  }
  _activePopoverKeys[anchorKey] = key;

  OverlayEntry? overlayEntry;
  overlayEntry = OverlayEntry(
    builder: (BuildContext context) => CDKDialogPopover(
      key: key,
      isAnimated: isAnimated,
      type: type,
      isTranslucent: isTranslucent,
      anchorKey: anchorKey,
      onHide: () {
        onHide?.call();
        overlayEntry?.remove();
        _activePopoverKeys.remove(anchorKey);
        // Close all other popovers
        while (_activePopoverKeys.isNotEmpty) {
          var refKey = _activePopoverKeys.values.first;
          var state = refKey.currentState as CDKDialogPopoverState;
          state.hide();
        }
      },
      child: child,
    ),
  );

  // Insereix l'OverlayEntry en l'overlay
  Overlay.of(context).insert(overlayEntry);
}