showNudgeOverlay function

void showNudgeOverlay(
  1. BuildContext context,
  2. Widget child,
  3. Map<String, dynamic> targetDetails
)

Implementation

void showNudgeOverlay(
  BuildContext context,
  Widget child,
  Map<String, dynamic> targetDetails,
) {
  NLogger.d(
    "showNudgeOverlay: _isNudgeOverlayVisible: $_isNudgeOverlayVisible",
  );
  if (_isNudgeOverlayVisible) {
    NLogger.d("Nudge overlay is already visible, skipping show");
    return;
  }

  NLogger.d("showNudgeOverlay called with targetDetails: $targetDetails");

  if (targetDetails['x'] == null ||
      targetDetails['y'] == null ||
      targetDetails['width'] == null ||
      targetDetails['height'] == null) {
    NLogger.e("Invalid target details provided for nudge overlay");
    return;
  }

  _overlayEntry = OverlayEntry(builder: (context) {
    return Stack(
      children: [
        Positioned.fill(
          child: ClipPath(
            clipper: RectangularHoleClipper(
              xPosition: targetDetails['x'],
              yPosition: targetDetails['y'],
              width: targetDetails['width'],
              height: targetDetails['height'],
            ),
            child: AbsorbPointer(
              absorbing: true,
              child: child, // background overlay, dimmed area
            ),
          ),
        ),

        // Overlay a transparent gesture-absorbing widget exactly in the hole area
        Positioned(
          left: targetDetails['x'],
          top: targetDetails['y'],
          width: targetDetails['width'],
          height: targetDetails['height'],
          child: GestureDetector(
            // Intercept scroll gestures
            onVerticalDragUpdate: (_) {},
            onHorizontalDragUpdate: (_) {},
            behavior: HitTestBehavior.translucent,
            child: const SizedBox.expand(),
          ),
        ),
      ],
    );
  });

  Nudge.nudgeNavigatorKey.currentState?.overlay?.insert(_overlayEntry!);
  _isNudgeOverlayVisible = true;
}