createShader method

  1. @override
Shader createShader(
  1. Rect bounds
)
override

Creates a Shader (i.e. a Gradient) from this object.

Implementation

@override
Shader createShader(Rect bounds) {
  final bool isObjectBoundingBox =
      unitMode == GradientUnitMode.objectBoundingBox;

  Matrix4 m4transform = transform == null
      ? Matrix4.identity()
      : Matrix4.fromFloat64List(transform!);

  if (isObjectBoundingBox) {
    final Matrix4 scale =
        affineMatrix(bounds.width, 0.0, 0.0, bounds.height, 0.0, 0.0);
    final Matrix4 translate =
        affineMatrix(1.0, 0.0, 0.0, 1.0, bounds.left, bounds.top);
    m4transform = translate.multiplied(scale)..multiply(m4transform);
  }

  return Gradient.radial(
    center,
    radius!,
    colors!,
    offsets,
    spreadMethod,
    m4transform.storage,
    focal,
    0.0,
  );
}