applyPaintTransform method

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

Multiply the transform from the parent's coordinate system to this box's coordinate system into the given transform.

This function is used to convert coordinate systems between boxes. Subclasses that apply transforms during painting should override this function to factor those transforms into the calculation.

The RenderBox implementation takes care of adjusting the matrix for the position of the given child as determined during layout and stored on the child's parentData in the BoxParentData.offset field.

Implementation

@override
void applyPaintTransform(RenderObject child, Matrix4 transform) {
  assert(child != null);
  assert(child.parent == this);
  assert(() {
    if (child.parentData is! BoxParentData) {
      throw FlutterError(
        '$runtimeType does not implement applyPaintTransform.\n'
        'The following $runtimeType object:\n'
        '  ${toStringShallow()}\n'
        '...did not use a BoxParentData class for the parentData field of the following child:\n'
        '  ${child.toStringShallow()}\n'
        'The $runtimeType class inherits from RenderBox. '
        'The default applyPaintTransform implementation provided by RenderBox assumes that the '
        'children all use BoxParentData objects for their parentData field. '
        'Since $runtimeType does not in fact use that ParentData class for its children, it must '
        'provide an implementation of applyPaintTransform that supports the specific ParentData '
        'subclass used by its children (which apparently is ${child.parentData.runtimeType}).'
      );
    }
    return true;
  }());
  final BoxParentData childParentData = child.parentData;
  final Offset offset = childParentData.offset;
  transform.translate(offset.dx, offset.dy);
}