getLayoutTransformTo function

Offset getLayoutTransformTo(
  1. RenderObject current,
  2. RenderObject ancestor, {
  3. bool excludeScrollOffset = false,
})

Implementation

Offset getLayoutTransformTo(RenderObject current, RenderObject ancestor, {bool excludeScrollOffset = false}) {
  final List<RenderObject> renderers = <RenderObject>[];
  for (RenderObject renderer = current; renderer != ancestor; renderer = renderer.parent!) {
    renderers.add(renderer);
    assert(renderer.parent != null);
  }
  renderers.add(ancestor);
  Offset offset = Offset.zero;
  final Matrix4 transform = Matrix4.identity();

  for (int index = renderers.length - 1; index > 0; index -= 1) {
    RenderObject parentRenderer = renderers[index];
    RenderObject childRenderer = renderers[index - 1];
    // Apply the layout transform for renderBoxModel and fallback to paint transform for other renderObject type.
    if (parentRenderer is RenderBoxModel) {
      offset += parentRenderer.obtainLayoutTransform(childRenderer, excludeScrollOffset);
    } else if (parentRenderer is RenderSliverRepaintProxy) {
      parentRenderer.applyLayoutTransform(childRenderer, transform, excludeScrollOffset);
    } else if (parentRenderer is RenderBox) {
      assert(childRenderer.parent == parentRenderer);
      if (childRenderer.parentData is BoxParentData) {
        offset += (childRenderer.parentData as BoxParentData).offset;
      }
    }
  }

  return offset;
}