getViewPosition static method

void getViewPosition(
  1. String listenerId,
  2. String clientElementId,
  3. double pixelRatio,
  4. int screenWidth,
  5. int screenHeight,
)

Implementation

static void getViewPosition(String listenerId, String clientElementId,
    double pixelRatio, int screenWidth, int screenHeight) {
  try {
    screenHeight = (MediaQuery.of(_ctx).size.height * pixelRatio).round();
    screenWidth = (MediaQuery.of(_ctx).size.width * pixelRatio).round();
    if (!clientElementId.contains("<'") && !clientElementId.contains("'>")) {
      clientElementId = "[<'$clientElementId'>]";
    }
    BuildContext? element = findViewByKey(clientElementId, _ctx);
    if (element != null) {
      plotlineDebugLog("PlotlineDebug: getViewPosition: element != null: $listenerId, $clientElementId, $pixelRatio, $screenWidth, $screenHeight");
      RenderBox box = element.findRenderObject() as RenderBox;
      Offset position = box.localToGlobal(Offset.zero);
      if (isWithinBounds(
          element, position, pixelRatio, screenWidth, screenHeight) && visibilityMap[clientElementId] == 100.0) {
        plotlineDebugLog("PlotlineDebug: getViewPosition: isWithinBounds: $listenerId, $clientElementId, $pixelRatio, $screenWidth, $screenHeight");
        Map<String, int?> positionMap = {
          "x": (position.dx * pixelRatio).round(),
          "y": (position.dy * pixelRatio).round(),
          "width": ((element.size?.width ?? 0) * pixelRatio).round(),
          "height": ((element.size?.height ?? 0) * pixelRatio).round()
        };
        plotlineDebugLog("PlotlineDebug: getViewPosition: positionMap: $positionMap $listenerId, $clientElementId, $pixelRatio, $screenWidth, $screenHeight");
        plotlineChannel.invokeMethod('getViewPosition', <String, dynamic>{
          "listenerId": listenerId,
          "position": positionMap
        });
        return;
      }
    }

    // Passing values which make the object get ignored
    Map<String, int?> positionMapDefault = {
      "x": -1,
      "y": -1,
      "width": -1,
      "height": -1
    };
    plotlineChannel.invokeMethod('getViewPosition', <String, dynamic>{
      "listenerId": listenerId,
      "position": positionMapDefault
    });
  } catch (e) {
    debugPrint("Error in getViewPosition: $e");
  }
}