getTransformTo method Null safety

Matrix4 getTransformTo (
  1. RenderObject? ancestor

Applies the paint transform up the tree to ancestor.

Returns a matrix that maps the local paint coordinate system to the coordinate system of ancestor.

If ancestor is null, this method returns a matrix that maps from the local paint coordinate system to the coordinate system of the PipelineOwner.rootNode. For the render tree owner by the RendererBinding (i.e. for the main render tree displayed on the device) this means that this method maps to the global coordinate system in logical pixels. To get physical pixels, use applyPaintTransform from the RenderView to further transform the coordinate.


Matrix4 getTransformTo(RenderObject? ancestor) {
  final bool ancestorSpecified = ancestor != null;
  if (ancestor == null) {
    final AbstractNode? rootNode = owner!.rootNode;
    if (rootNode is RenderObject)
      ancestor = rootNode;
  final List<RenderObject> renderers = <RenderObject>[];
  for (RenderObject renderer = this; renderer != ancestor; renderer = renderer.parent as RenderObject) {
    assert(renderer != null); // Failed to find ancestor in parent chain.
  if (ancestorSpecified)
  final Matrix4 transform = Matrix4.identity();
  for (int index = renderers.length - 1; index > 0; index -= 1) {
    renderers[index].applyPaintTransform(renderers[index - 1], transform);
  return transform;