onGetNodeForLocation method

void onGetNodeForLocation(
  1. int? id,
  2. Map<String, dynamic> params
)

Implementation

void onGetNodeForLocation(int? id, Map<String, dynamic> params) {
  int x = params['x'];
  int y = params['y'];

  RenderBox rootRenderObject = elementManager.getRootRenderBox();
  BoxHitTestResult result = BoxHitTestResult();
  rootRenderObject.hitTest(result, position: Offset(x.toDouble(), y.toDouble()));
  if (result.path.first.target is RenderBoxModel) {
    RenderBoxModel lastHitRenderBoxModel = result.path.first.target as RenderBoxModel;
    int targetId = lastHitRenderBoxModel.renderStyle.target.targetId;
    sendToFrontend(id, JSONEncodableMap({
      'backendId': targetId,
      'frameId': DEFAULT_FRAME_ID,
      'nodeId': targetId,
    }));
  } else {
    sendToFrontend(id, null);
  }
}