showDraggable static method

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

Implementation

static void showDraggable({
  required GlobalKey key,
  required BuildContext context,
  required GlobalKey anchorKey,
  bool isAnimated = false,
  bool isTranslucent = false,
  Function? onHide,
  required Widget child,
}) {
  if (_activeDraggableKeys.containsKey(anchorKey)) {
    moveDraggableToTop(context, anchorKey);
    return;
  }

  _activeDraggableKeys[anchorKey] = key;

  OverlayEntry? overlayEntry;
  overlayEntry = OverlayEntry(
    builder: (BuildContext context) => CDKDialogDraggable(
      key: key,
      anchorKey: anchorKey,
      isAnimated: isAnimated,
      isTranslucent: isTranslucent,
      onHide: () {
        onHide?.call();
        overlayEntry?.remove();
        _activeDraggableKeys.remove(anchorKey);
      },
      child: child,
    ),
  );

  _activeDraggableEntries[anchorKey] = overlayEntry;

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