applyTransform method Null safety

  1. @override
void applyTransform(
  1. Layer? child,
  2. Matrix4 transform
)
override

Applies the transform that would be applied when compositing the given child to the given matrix.

Specifically, this should apply the transform that is applied to child's origin. When using applyTransform with a chain of layers, results will be unreliable unless the deepest layer in the chain collapses the layerOffset in addToScene to zero, meaning that it passes Offset.zero to its children, and bakes any incoming layerOffset into the SceneBuilder as (for instance) a transform (which is then also included in the transformation applied by applyTransform).

For example, if addToScene applies the layerOffset and then passes Offset.zero to the children, then it should be included in the transform applied here, whereas if addToScene just passes the layerOffset to the child, then it should not be included in the transform applied here.

This method is only valid immediately after addToScene has been called, before any of the properties have been changed.

The default implementation does nothing, since ContainerLayer, by default, composites its children at the origin of the ContainerLayer itself.

The child argument should generally not be null, since in principle a layer could transform each child independently. However, certain layers may explicitly allow null as a value, for example if they know that they transform all their children identically.

The transform argument must not be null.

Used by FollowerLayer to transform its child to a LeaderLayer's position.

Implementation

@override
void applyTransform(Layer? child, Matrix4 transform) {
  assert(child != null);
  assert(transform != null);
  if (_lastTransform != null) {
    transform.multiply(_lastTransform!);
  } else {
    transform.multiply(Matrix4.translationValues(unlinkedOffset!.dx, unlinkedOffset!.dy, 0));
  }
}