transform method Null safety
- Rect bounds,
- {TextDirection? textDirection}
override
When a Gradient creates its Shader, it will call this method to determine what transform to apply to the shader for the given Rect and TextDirection.
Implementers may return null from this method, which achieves the same final effect as returning Matrix4.identity.
Implementation
@override
Matrix4 transform(Rect bounds, {TextDirection? textDirection}) {
assert(bounds != null);
final double sinRadians = math.sin(radians);
final double oneMinusCosRadians = 1 - math.cos(radians);
final Offset center = bounds.center;
final double originX = sinRadians * center.dy + oneMinusCosRadians * center.dx;
final double originY = -sinRadians * center.dx + oneMinusCosRadians * center.dy;
return Matrix4.identity()
..translate(originX, originY)
..rotateZ(radians);
}