nudgeTooltip function

void nudgeTooltip(
  1. BuildContext context,
  2. Root rootData,
  3. String eventName
)

Implementation

void nudgeTooltip(
  BuildContext context,
  Root rootData,
  String eventName,
) async {
  OverlayEntry? overlayForegroundEntry;
  OverlayEntry? overlayBackgroundEntry;

  Nudge.getInstance().submit(
    taskId: NudgeNudgesUi.taskID!,
    response: [
      {
        "root_id": rootData.id,
        "widget_id": rootData.components[NudgeNudgesUi.currentNudgeIndex].id,
        "answers": [],
        "action": "OPENED",
      }
    ],
    onSuccessCallback: (data) {
      print("Tooltip Opened, $data");
    },
    onErrorCallback: (error, stacktrace) {
      print("Error: $error");
    },
  );

  NudgeNudgesUi.componentName = rootData
          .components[NudgeNudgesUi.currentNudgeIndex]
          .componentProps
          .elementId ??
      "";

  print('Component Name: ${NudgeNudgesUi.componentName}');

  String? referenceSize = rootData.rootProps.size;

  Size referenceDimensions = Size(
    int.parse(referenceSize.split('x')[0]).toDouble(),
    int.parse(referenceSize.split('x')[1]).toDouble(),
  );

  int referenceHeight = referenceDimensions.height.toInt();
  int referenceWidth = referenceDimensions.width.toInt();

  Size screenSize = MediaQuery.of(context).size;
  double screenHeight = screenSize.height;
  double screenWidth = screenSize.width;

  double scaleHeight = screenHeight / referenceHeight;
  double scaleWidth = screenWidth / referenceWidth;

  // Color fillColor = HexColor.fromHex(
  //   rootData.components[NudgeNudgesUi.currentNudgeIndex].componentProps
  //           .bgColor ??
  //       "#000000",
  // );

  overlayBackgroundEntry = OverlayEntry(
    builder: (context) {
      return Positioned(
        top: 0,
        left: 0,
        height: MediaQuery.of(context).size.height,
        width: MediaQuery.of(context).size.width,
        child: GestureDetector(
          onTap: () {
            overlayForegroundEntry?.remove();
            overlayBackgroundEntry?.remove();
            Nudge.getInstance().submit(
              taskId: NudgeNudgesUi.taskID!,
              response: [
                {
                  "root_id": rootData.id,
                  "widget_id":
                      rootData.components[NudgeNudgesUi.currentNudgeIndex].id,
                  "answers": [],
                  "action": "DISMISSED",
                }
              ],
              onSuccessCallback: (data) {},
              onErrorCallback: (error, stacktrace) {},
            );
          },
          child: AbsorbPointer(
            child: Container(
              color: Colors.white.withOpacity(0),
            ),
          ),
        ),
      );
    },
  );

  bool isPositionBased = rootData.components[NudgeNudgesUi.currentNudgeIndex]
          .componentProps.isPositionBased ??
      false;

  NudgeProviderState.navigatorKey.currentState?.overlay
      ?.insert(overlayBackgroundEntry);

  WidgetDetails? targetView = NudgeWidgetTracker.findWidgetPositionByLabel(
    NudgeNudgesUi.componentName,
    scaleWidth,
    scaleHeight,
  );

  if (targetView == null && !isPositionBased) {
    overlayBackgroundEntry.remove();
  }

  final NudgeNudgesUi nudgeNudgesUi = NudgeNudgesUi();

  Color fillColor = HexColor.fromHex(rootData
              .components[NudgeNudgesUi.currentNudgeIndex]
              .componentProps
              .overlayColor ??
          "#000000")
      .withOpacity(
    rootData.components[NudgeNudgesUi.currentNudgeIndex].componentProps
            .overlayOpacity! /
        100,
  );

  nudgeNudgesUi
      .scrollToTargetWidget(targetView?.key, isPositionBased: isPositionBased)
      .then(
        (value) => Future.delayed(
          const Duration(milliseconds: 100),
        ),
      )
      .then((value) {
    WidgetDetails? targetViewMain =
        NudgeWidgetTracker.findWidgetPositionByLabel(
      NudgeNudgesUi.componentName,
      scaleWidth,
      scaleHeight,
    );

    logger.i("""
      Component Height: ${NudgeNudgesUi.componentHeight},
      Component Width: ${NudgeNudgesUi.componentWidth},
      Component X: ${NudgeNudgesUi.componentX},
      Component Y: ${NudgeNudgesUi.componentY}
    """);

    if (isPositionBased) {
      logger.e("Position Based");
      NudgeNudgesUi.componentY = rootData
              .components[NudgeNudgesUi.currentNudgeIndex]
              .componentProps
              .elementProps!
              .y
              .roundToDouble() *
          scaleHeight;
      NudgeNudgesUi.componentX = rootData
              .components[NudgeNudgesUi.currentNudgeIndex]
              .componentProps
              .elementProps!
              .x
              .roundToDouble() *
          scaleWidth;
      NudgeNudgesUi.componentHeight = rootData
              .components[NudgeNudgesUi.currentNudgeIndex]
              .componentProps
              .elementProps!
              .height
              .roundToDouble() *
          scaleHeight;
      NudgeNudgesUi.componentWidth = rootData
              .components[NudgeNudgesUi.currentNudgeIndex]
              .componentProps
              .elementProps!
              .width
              .roundToDouble() *
          scaleWidth;

      logger.i("""
        Component Height: ${NudgeNudgesUi.componentHeight},
        Component Width: ${NudgeNudgesUi.componentWidth},
        Component X: ${NudgeNudgesUi.componentX},
        Component Y: ${NudgeNudgesUi.componentY}
      """);
    } else if (targetViewMain != null) {
      NudgeNudgesUi.componentHeight = targetViewMain.height;
      NudgeNudgesUi.componentWidth = targetViewMain.width;

      NudgeNudgesUi.componentX = targetViewMain.x;
      NudgeNudgesUi.componentY = targetViewMain.y;
    }

    // print(
    //   'Component Height: ${NudgeNudgesUi.componentHeight}, Component Width: ${NudgeNudgesUi.componentWidth}, Component X: ${NudgeNudgesUi.componentX}, Component Y: ${NudgeNudgesUi.componentY}',
    // );

    logger.i(
      "isPositionBased: ${rootData.components[NudgeNudgesUi.currentNudgeIndex].componentProps.isPositionBased}",
    );

    ImageSize imageSize = extractSize(
      rootData.rootProps.size,
    );

    try {
      nudgeNudgesUi.heightRatio =
          imageSize.height / MediaQuery.of(context).size.height;
      nudgeNudgesUi.widthRatio =
          imageSize.width / MediaQuery.of(context).size.width;
    } catch (e) {
      if (kDebugMode) {
        print(e);
      }
    }

    double top;
    double left;

    String tooltipPosition = rootData
            .components[NudgeNudgesUi.currentNudgeIndex]
            .componentProps
            .tooltipPosition ??
        'top';
    String tooltipArrowPosition = rootData
            .components[NudgeNudgesUi.currentNudgeIndex]
            .componentProps
            .tooltipArrow ??
        'top';

    // X position of Tooltip
    if (tooltipPosition == "bottom" && tooltipArrowPosition == "center") {
      left = NudgeNudgesUi.componentX + NudgeNudgesUi.componentWidth / 2;
    } else if (tooltipPosition == "bottom" && tooltipArrowPosition == "left") {
      left = NudgeNudgesUi.componentX + NudgeNudgesUi.componentWidth / 2 - 10;
    } else if (tooltipPosition == "bottom" && tooltipArrowPosition == "right") {
      left = NudgeNudgesUi.componentX - NudgeNudgesUi.componentWidth / 2 + 10;
    } else if (tooltipPosition == "top" && tooltipArrowPosition == "center") {
      left = NudgeNudgesUi.componentX + NudgeNudgesUi.componentWidth / 2;
    } else if (tooltipPosition == "top" && tooltipArrowPosition == "left") {
      left = NudgeNudgesUi.componentX + NudgeNudgesUi.componentWidth / 2 - 10;
    } else if (tooltipPosition == "top" && tooltipArrowPosition == "right") {
      left = NudgeNudgesUi.componentX + NudgeNudgesUi.componentWidth / 2 + 10;
    } else if (tooltipPosition == "left") {
      left = NudgeNudgesUi.componentX - 10;
    } else if (tooltipPosition == "right") {
      left = NudgeNudgesUi.componentX + NudgeNudgesUi.componentWidth / 2 + 10;
    } else {
      left = NudgeNudgesUi.componentY / 2;
    }

    // Y position of Tooltip
    if (tooltipPosition == "bottom" && tooltipArrowPosition == "center") {
      top = NudgeNudgesUi.componentY + NudgeNudgesUi.componentHeight;
    } else if (tooltipPosition == "bottom" && tooltipArrowPosition == "left") {
      top = NudgeNudgesUi.componentY + NudgeNudgesUi.componentHeight;
    } else if (tooltipPosition == "bottom" && tooltipArrowPosition == "right") {
      top = NudgeNudgesUi.componentY + NudgeNudgesUi.componentHeight;
    } else if (tooltipPosition == "top" && tooltipArrowPosition == "center") {
      top = NudgeNudgesUi.componentY - 10; // Subtracting 30  (height of arrow)
    } else if (tooltipPosition == "top" && tooltipArrowPosition == "left") {
      top = NudgeNudgesUi.componentY - 10; // Subtracting 30  (height of arrow)
    } else if (tooltipPosition == "top" && tooltipArrowPosition == "right") {
      top = NudgeNudgesUi.componentY - 10; // Subtracting 30  (height of arrow)
    } else if (tooltipPosition == "left") {
      top = NudgeNudgesUi.componentY + NudgeNudgesUi.componentHeight / 2;
    } else if (tooltipPosition == "right") {
      top = NudgeNudgesUi.componentY + NudgeNudgesUi.componentHeight / 2;
    } else {
      top = NudgeNudgesUi.componentY;
    }

    Color fillColor = HexColor.fromHex(
      rootData.components[NudgeNudgesUi.currentNudgeIndex].componentProps
              .bgColor ??
          "#000000",
    );

    Color overlayFillColor = HexColor.fromHex(rootData
                .components[NudgeNudgesUi.currentNudgeIndex]
                .componentProps
                .overlayColor ??
            "#000000")
        .withOpacity(
      rootData.components[NudgeNudgesUi.currentNudgeIndex].componentProps
              .overlayOpacity! /
          100,
    );

    overlayForegroundEntry = OverlayEntry(builder: (context) {
      return Positioned(
        top: top,
        left: left,
        child: tooltipPosition == 'top' || tooltipPosition == 'bottom'
            ? Opacity(
                opacity: 0,
                child: Column(
                  crossAxisAlignment: () {
                    if (tooltipArrowPosition == "center") {
                      return CrossAxisAlignment.center;
                    } else if (tooltipArrowPosition == "left") {
                      return CrossAxisAlignment.start;
                    } else if (tooltipArrowPosition == "right") {
                      return CrossAxisAlignment.end;
                    } else {
                      return CrossAxisAlignment.center;
                    }
                  }(),
                  children: [
                    if (tooltipPosition == "bottom")
                      Padding(
                        padding: const EdgeInsets.only(
                          left: 8.0,
                          right: 8.0,
                        ),
                        child: CustomPaint(
                          size: const Size(20, 10), // Set the size explicitly
                          painter: TrianglePainter(
                            color: fillColor,
                            arrowDirection: ArrowDirection.up,
                          ),
                        ),
                      ),
                    UIPage(
                      rootId: rootData.id,
                      taskId: NudgeNudgesUi.taskID!,
                      key: nudgeNudgesUi.contentKey,
                      nudgeProps: rootData
                          .components[NudgeNudgesUi.currentNudgeIndex]
                          .componentProps
                          .toJson(),
                      type: () {
                        if (rootData.components[NudgeNudgesUi.currentNudgeIndex]
                                .componentProps.orientation ==
                            "vertical") {
                          return 20;
                        } else {
                          return 21;
                        }
                      }(),
                      json: rootData
                          .components[NudgeNudgesUi.currentNudgeIndex].widgets!,
                      assetUrl: assetUrl,
                      assets: Nudge.assets,
                    ),
                    if (tooltipPosition == "top")
                      Padding(
                        padding: EdgeInsets.only(
                          left: rootData
                              .components[NudgeNudgesUi.currentNudgeIndex]
                              .componentProps
                              .roundness!
                              .toDouble(),
                          right: rootData
                              .components[NudgeNudgesUi.currentNudgeIndex]
                              .componentProps
                              .roundness!
                              .toDouble(),
                        ),
                        child: CustomPaint(
                          size: const Size(20, 10),
                          painter: TrianglePainter(
                            color: fillColor,
                            arrowDirection: ArrowDirection.down,
                          ),
                        ),
                      ),
                  ],
                ),
              )
            : Opacity(
                opacity: 0,
                child: Row(
                  mainAxisAlignment: () {
                    if (tooltipArrowPosition == "center") {
                      return MainAxisAlignment.center;
                    } else if (tooltipArrowPosition == "left") {
                      return MainAxisAlignment.start;
                    } else if (tooltipArrowPosition == "right") {
                      return MainAxisAlignment.end;
                    } else {
                      return MainAxisAlignment.center;
                    }
                  }(),
                  children: [
                    if (tooltipPosition == "right")
                      Padding(
                        padding: const EdgeInsets.only(
                          top: 0.0,
                          bottom: 0.0,
                          right: 10,
                        ),
                        child: CustomPaint(
                          size: const Size(10, 20), // Set the size explicitly
                          painter: TrianglePainter(
                            color: fillColor,
                            arrowDirection: ArrowDirection.left,
                          ),
                        ),
                      ),
                    UIPage(
                      rootId: rootData.id,
                      taskId: NudgeNudgesUi.taskID!,
                      key: nudgeNudgesUi.contentKey,
                      nudgeProps: rootData
                          .components[NudgeNudgesUi.currentNudgeIndex]
                          .componentProps
                          .toJson(),
                      type: () {
                        if (rootData.components[NudgeNudgesUi.currentNudgeIndex]
                                .componentProps.orientation ==
                            "vertical") {
                          return 20;
                        } else {
                          return 21;
                        }
                      }(),
                      json: rootData
                          .components[NudgeNudgesUi.currentNudgeIndex].widgets!,
                      assetUrl: assetUrl,
                      assets: Nudge.assets,
                    ),
                    if (tooltipPosition == "left")
                      Padding(
                        padding: const EdgeInsets.only(
                          top: 0.0,
                          bottom: 0.0,
                          right: 10,
                        ),
                        child: CustomPaint(
                          size: const Size(10, 20), // Set the size explicitly
                          painter: TrianglePainter(
                            color: fillColor,
                            arrowDirection: ArrowDirection.right,
                          ),
                        ),
                      ),
                  ],
                ),
              ),
      );
    });

    NudgeProviderState.navigatorKey.currentState?.overlay
        ?.insert(overlayForegroundEntry!);

    WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
      if (nudgeNudgesUi.contentKey.currentContext != null) {
        NudgeNudgesUi.tooltipContainerHeight =
            nudgeNudgesUi.contentKey.currentContext!.size!.height;
        NudgeNudgesUi.tooltipContainerWidth =
            nudgeNudgesUi.contentKey.currentContext!.size!.width;

        double newTop = top;
        double newLeft = left;

        // New Left Position of Tool Tip
        if (tooltipPosition == "bottom" && tooltipArrowPosition == "center") {
          newLeft = left - NudgeNudgesUi.tooltipContainerWidth / 2;
        } else if (tooltipPosition == "bottom" &&
            tooltipArrowPosition == "left") {
          newLeft = left - 10;
        } else if (tooltipPosition == "bottom" &&
            tooltipArrowPosition == "right") {
          newLeft = left - NudgeNudgesUi.tooltipContainerWidth / 2 - 10;
        } else if (tooltipPosition == "top" &&
            tooltipArrowPosition == "center") {
          newLeft = left - NudgeNudgesUi.tooltipContainerWidth / 2 - 10;
        } else if (tooltipPosition == "top" && tooltipArrowPosition == "left") {
          newLeft = left - 10;
        } else if (tooltipPosition == "top" &&
            tooltipArrowPosition == "right") {
          newLeft = left - NudgeNudgesUi.tooltipContainerWidth + 10;
        } else if (tooltipPosition == "left") {
          newLeft = left - NudgeNudgesUi.tooltipContainerWidth;
        } else if (tooltipPosition == "right") {
          newLeft = left +
              NudgeNudgesUi.tooltipContainerWidth / 2 -
              NudgeNudgesUi.componentWidth / 2 +
              10.0;
        } else {
          newLeft = left;
        }

        // New Top Position of Tool Tip
        if (tooltipPosition == "bottom" && tooltipArrowPosition == "center") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top - NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else if (tooltipPosition == "bottom" &&
            tooltipArrowPosition == "left") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top - NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else if (tooltipPosition == "bottom" &&
            tooltipArrowPosition == "right") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top - NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else if (tooltipPosition == "top" &&
            tooltipArrowPosition == "center") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top -
                NudgeNudgesUi.tooltipContainerHeight -
                NudgeKeyUtility.offset;
          } else {
            newTop = top - NudgeNudgesUi.tooltipContainerHeight;
          }
        } else if (tooltipPosition == "top" && tooltipArrowPosition == "left") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top -
                NudgeNudgesUi.tooltipContainerHeight -
                NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else if (tooltipPosition == "top" &&
            tooltipArrowPosition == "right") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top -
                NudgeNudgesUi.tooltipContainerHeight -
                NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else if (tooltipPosition == "left") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top -
                NudgeNudgesUi.tooltipContainerHeight / 2 -
                NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else if (tooltipPosition == "right") {
          if (NudgeKeyUtility.offset >= 0) {
            newTop = top -
                NudgeNudgesUi.tooltipContainerHeight / 2 -
                NudgeKeyUtility.offset;
          } else {
            newTop = top;
          }
        } else {
          newTop = top;
        }

        overlayForegroundEntry?.remove();

        logger.e("UPDATING NEXT CALLBACK, TOOLTIP!!!");
        Future<void> newNextCallback(nextRootId) async {
          logger.e("NEXT CALLBACK, TOOLTIP!!!!, $nextRootId");
          if (NudgeNudgesUi.currentNudgeIndex ==
              NudgeNudgesUi.nudgesLength - 1) {
            overlayBackgroundEntry?.remove();
            overlayForegroundEntry?.remove();
            return;
          }
          NudgeNudgesUi.currentNudgeIndex++;

          if (rootData.components[NudgeNudgesUi.currentNudgeIndex]
                  .componentProps.type ==
              "spotlight") {
            overlayForegroundEntry?.remove();
            overlayBackgroundEntry?.remove();
            nudgeSpotlight(context, rootData, eventName);
          } else if (rootData.components[NudgeNudgesUi.currentNudgeIndex]
                  .componentProps.type ==
              "coachmark") {
            overlayForegroundEntry?.remove();
            overlayBackgroundEntry?.remove();
            nudgeCoachMark(context, rootData, eventName);
          } else if (rootData.components[NudgeNudgesUi.currentNudgeIndex]
                  .componentProps.type ==
              "tooltip") {
            overlayForegroundEntry?.remove();
            overlayBackgroundEntry?.remove();
            nudgeTooltip(context, rootData, eventName);
          }
        }

        Future<void> newCloseCallback(param) async {
          overlayBackgroundEntry?.remove();
          overlayForegroundEntry?.remove();
        }

        CentralDataRepository.updateInstance(
          NudgeNudgesUi.taskID!,
          closeCallback: ({
            rootId,
            widgetId,
            widgetType,
            context,
          }) async {
            overlayBackgroundEntry?.remove();
            overlayForegroundEntry?.remove();

            Nudge.getInstance().submit(
              taskId: NudgeNudgesUi.taskID!,
              response: [
                {
                  "root_id": rootData.id,
                  "widget_id":
                      rootData.components[NudgeNudgesUi.currentNudgeIndex].id,
                  "answers": [],
                  "action": "DISMISSED",
                }
              ],
              onSuccessCallback: (data) {},
              onErrorCallback: (error, stacktrace) {},
            );
          },
          nextCallBack: newNextCallback,
        );

        logger.e("Fill Color: $overlayFillColor");

        overlayForegroundEntry = OverlayEntry(builder: (context) {
          return ClipPath(
            clipper: RectangularHoleClipper(
              xPosition: NudgeNudgesUi.componentX,
              yPosition: NudgeNudgesUi.componentY,
              width: NudgeNudgesUi.componentWidth,
              height: NudgeNudgesUi.componentHeight,
            ),
            child: Stack(
              children: [
                GestureDetector(
                  onTap: () {
                    overlayBackgroundEntry!.remove();
                    overlayForegroundEntry!.remove();
                    Nudge.getInstance().submit(
                      taskId: NudgeNudgesUi.taskID!,
                      response: [
                        {
                          "root_id": rootData.id,
                          "widget_id": rootData
                              .components[NudgeNudgesUi.currentNudgeIndex].id,
                          // "component_id": rootData
                          //     .components[NudgeNudgesUi.currentNudgeIndex].id,
                          // "wt": null,
                          "answers": [],
                          "action": "DISMISSED",
                        }
                      ],
                      onSuccessCallback: (response) {
                        print("Spotlight Dismissed, $response");
                      },
                      onErrorCallback: (error, stackTrace) {
                        print("Error: $error");
                      },
                    );
                  },
                  child: Container(
                    color: overlayFillColor,
                  ),
                ),
                Positioned(
                  top: newTop,
                  left: newLeft,
                  child: tooltipPosition == 'top' || tooltipPosition == 'bottom'
                      ? Column(
                          crossAxisAlignment: () {
                            if (tooltipArrowPosition == "center") {
                              return CrossAxisAlignment.center;
                            } else if (tooltipArrowPosition == "left") {
                              return CrossAxisAlignment.start;
                            } else if (tooltipArrowPosition == "right") {
                              return CrossAxisAlignment.end;
                            } else {
                              return CrossAxisAlignment.center;
                            }
                          }(),
                          children: [
                            if (tooltipPosition == "bottom")
                              Padding(
                                padding: const EdgeInsets.only(
                                  left: 16.0,
                                  right: 16.0,
                                ),
                                child: CustomPaint(
                                  size: const Size(
                                      20, 10), // Set the size explicitly
                                  painter: TrianglePainter(
                                    color: fillColor,
                                    arrowDirection: ArrowDirection.up,
                                  ),
                                ),
                              ),
                            UIPage(
                              rootId: rootData.id,
                              taskId: NudgeNudgesUi.taskID!,
                              width: NudgeNudgesUi.tooltipContainerWidth,
                              height: NudgeNudgesUi.tooltipContainerHeight,
                              // callBack: (widgetId, target, clickType) {},
                              key: nudgeNudgesUi.contentKey,
                              nudgeProps: rootData
                                  .components[NudgeNudgesUi.currentNudgeIndex]
                                  .componentProps
                                  .toJson(),
                              type: () {
                                if (rootData
                                        .components[
                                            NudgeNudgesUi.currentNudgeIndex]
                                        .componentProps
                                        .orientation ==
                                    "vertical") {
                                  return 20;
                                } else {
                                  return 21;
                                }
                              }(),
                              json: rootData
                                  .components[NudgeNudgesUi.currentNudgeIndex]
                                  .widgets!,
                              assetUrl: assetUrl,
                              assets: Nudge.assets,
                            ),
                            if (tooltipPosition == "top")
                              Padding(
                                padding: EdgeInsets.only(
                                  left: rootData
                                      .components[
                                          NudgeNudgesUi.currentNudgeIndex]
                                      .componentProps
                                      .roundness!
                                      .toDouble(),
                                  right: rootData
                                      .components[
                                          NudgeNudgesUi.currentNudgeIndex]
                                      .componentProps
                                      .roundness!
                                      .toDouble(),
                                ),
                                child: CustomPaint(
                                  size: const Size(20, 10),
                                  painter: TrianglePainter(
                                    color: fillColor,
                                    arrowDirection: ArrowDirection.down,
                                  ),
                                ),
                              ),
                          ],
                        )
                      : Row(
                          mainAxisAlignment: () {
                            if (tooltipArrowPosition == "center") {
                              return MainAxisAlignment.center;
                            } else if (tooltipArrowPosition == "left") {
                              return MainAxisAlignment.start;
                            } else if (tooltipArrowPosition == "right") {
                              return MainAxisAlignment.end;
                            } else {
                              return MainAxisAlignment.center;
                            }
                          }(),
                          children: [
                            if (tooltipPosition == "right")
                              Padding(
                                padding: const EdgeInsets.only(
                                  top: 0.0,
                                  bottom: 0.0,
                                  left: 10,
                                ),
                                child: CustomPaint(
                                  size: const Size(
                                      10, 20), // Set the size explicitly
                                  painter: TrianglePainter(
                                    color: fillColor,
                                    arrowDirection: ArrowDirection.left,
                                  ),
                                ),
                              ),
                            UIPage(
                              rootId: rootData.id,
                              taskId: NudgeNudgesUi.taskID!,
                              height: NudgeNudgesUi.tooltipContainerHeight,
                              width: NudgeNudgesUi.tooltipContainerWidth,
                              callBack: ({
                                widgetId,
                                target,
                                clickType,
                                widgetType,
                              }) {
                                Nudge.getInstance().submit(
                                  taskId: NudgeNudgesUi.taskID!,
                                  response: [
                                    {
                                      "root_id": rootData.id,
                                      "widget_id": widgetId,
                                      // "component_id": rootData
                                      //     .components[NudgeNudgesUi.currentNudgeIndex].id,
                                      "wt": widgetType,
                                      "answers": [],
                                      "action": "CTA_CLICKED",
                                    }
                                  ],
                                  onSuccessCallback: (response) {
                                    print("Coachmark CTA Clicked, $response");
                                  },
                                  onErrorCallback: (error, stackTrace) {
                                    print("Coachmark CTA Clicked Error");
                                  },
                                );

                                // clickType = "NEXT_NUDGE";
                                if (clickType == "DEEP_LINK") {
                                  _launchUrl(target!);
                                } else if (clickType == "EXTERNAL_URL") {
                                  _launchUrl(target!);
                                } else if (clickType == "NEXT_NUDGE") {
                                  if (NudgeNudgesUi.currentNudgeIndex ==
                                      NudgeNudgesUi.nudgesLength - 1) {
                                    overlayBackgroundEntry?.remove();
                                    overlayForegroundEntry?.remove();
                                    return;
                                  }

                                  NudgeNudgesUi.currentNudgeIndex++;

                                  if (rootData
                                          .components[
                                              NudgeNudgesUi.currentNudgeIndex]
                                          .componentProps
                                          .type ==
                                      "spotlight") {
                                    print("Spotlight");
                                    overlayForegroundEntry?.remove();
                                    overlayBackgroundEntry?.remove();
                                    nudgeSpotlight(
                                        context, rootData, eventName);
                                  } else if (rootData
                                          .components[
                                              NudgeNudgesUi.currentNudgeIndex]
                                          .componentProps
                                          .type ==
                                      "coachmark") {
                                    print("Coachmark");
                                    overlayForegroundEntry?.remove();
                                    overlayBackgroundEntry?.remove();
                                    nudgeCoachMark(
                                        context, rootData, eventName);
                                  } else if (rootData
                                          .components[
                                              NudgeNudgesUi.currentNudgeIndex]
                                          .componentProps
                                          .type ==
                                      "tooltip") {
                                    print("Tooltip");
                                    overlayForegroundEntry?.remove();
                                    overlayBackgroundEntry?.remove();
                                    nudgeTooltip(context, rootData, eventName);
                                  }
                                } else {
                                  overlayBackgroundEntry?.remove();
                                  overlayForegroundEntry?.remove();
                                  return;
                                }
                              },
                              nudgeProps: rootData
                                  .components[NudgeNudgesUi.currentNudgeIndex]
                                  .componentProps
                                  .toJson(),
                              type: () {
                                if (rootData
                                        .components[
                                            NudgeNudgesUi.currentNudgeIndex]
                                        .componentProps
                                        .orientation ==
                                    "vertical") {
                                  return 20;
                                } else {
                                  return 21;
                                }
                              }(),
                              json: rootData
                                  .components[NudgeNudgesUi.currentNudgeIndex]
                                  .widgets!,
                              assetUrl: assetUrl,
                              assets: Nudge.assets,
                            ),
                            if (tooltipPosition == "left")
                              Padding(
                                padding: const EdgeInsets.only(
                                  top: 0.0,
                                  bottom: 0.0,
                                  right: 10,
                                ),
                                child: CustomPaint(
                                  size: const Size(
                                      10, 20), // Set the size explicitly
                                  painter: TrianglePainter(
                                    color: fillColor,
                                    arrowDirection: ArrowDirection.right,
                                  ),
                                ),
                              ),
                          ],
                        ),
                ),
              ],
            ),
          );
        });

        WidgetDetails? targetViewFinal =
            NudgeWidgetTracker.findWidgetPositionByLabel(
          NudgeNudgesUi.componentName,
          scaleWidth,
          scaleHeight,
        );

        if (targetViewFinal != null) {
          NudgeProviderState.navigatorKey.currentState?.overlay
              ?.insert(overlayForegroundEntry!);
        } else if (isPositionBased) {
          NudgeProviderState.navigatorKey.currentState?.overlay
              ?.insert(overlayForegroundEntry!);
        }
      } else {
        if (kDebugMode) {
          print("Content Key is null");
        }
      }
    });

    WidgetDetails? targetViewFinal =
        NudgeWidgetTracker.findWidgetPositionByLabel(
      NudgeNudgesUi.componentName,
      scaleWidth,
      scaleHeight,
    );

    if (targetViewFinal != null) {
      if (targetViewFinal.x == targetView?.x &&
          targetViewFinal.y == targetView?.y) {
        overlayForegroundEntry?.remove();
        NudgeProviderState.navigatorKey.currentState!.overlay
            ?.insert(overlayForegroundEntry!);
      }
    } else if (isPositionBased) {
      overlayForegroundEntry?.remove();
      NudgeProviderState.navigatorKey.currentState?.overlay
          ?.insert(overlayForegroundEntry!);
    }
  });
}