applyPaintTransform method

  1. @override
void applyPaintTransform(
  1. covariant RenderBox child,
  2. Matrix4 transform
)
override

Tells the framework how our render object visually transformed the given child.

In our case, we only have one child, so we immediately know exactly how we transformed it. If we had multiple children, we'd need to inspect the ParentData of the child to apply the appropriate transform.

This method makes possible all situations where UI needs to know its orientation in relation to the screen, or to some ancestor or cousin in the tree. E.g.:

  • Tells semantic system the orientation for the green bounding box.
  • Makes it possible for RenderBoxs to calculate "local to global" and "global to local".
  • Overlay positioning.

THIS METHOD IS CRITICAL. If you mess this up, you might not immediately notice it, but various things will be broken for reasons that you'll struggle to figure out.

Implementation

@override
void applyPaintTransform(RenderBox child, Matrix4 transform) {
  transform.multiply(_createRotationMatrix());
}