applyPaintTransform method Null safety

  1. @override
void applyPaintTransform(
  1. covariant RenderObject child,
  2. 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.fromParts(<DiagnosticsNode>[
        ErrorSummary('$runtimeType does not implement applyPaintTransform.'),
        describeForError('The following $runtimeType object'),
        child.describeForError('...did not use a BoxParentData class for the parentData field of the following child'),
        ErrorDescription('The $runtimeType class inherits from RenderBox.'),
        ErrorHint(
          '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! as BoxParentData;
  final Offset offset = childParentData.offset;
  transform.translate(offset.dx, offset.dy);
}