findComponentOffset static method

Offset findComponentOffset(
  1. String nodeId,
  2. Alignment alignment, [
  3. Finder? finder
])

Returns the (x,y) offset for the component which renders the node with the given nodeId.

By default, this method expects a single SuperReader in the widget tree and finds it byType. To specify one SuperReader among many, pass a superDocumentFinder.

Implementation

static Offset findComponentOffset(String nodeId, Alignment alignment, [Finder? finder]) {
  final documentLayout = _findDocumentLayout(finder);
  final component = documentLayout.getComponentByNodeId(nodeId);
  assert(component != null);
  final componentBox = component!.context.findRenderObject() as RenderBox;
  final rect = componentBox.localToGlobal(Offset.zero) & componentBox.size;
  return alignment.withinRect(rect);
}