paint method

  1. @override
void paint(
  1. GaugeAxis axis,
  2. RadialGaugeLayout layout,
  3. Canvas canvas,
  4. double progress,
)
override

Implementation

@override
void paint(
  GaugeAxis axis,
  RadialGaugeLayout layout,
  Canvas canvas,
  double progress,
) {
  final progressBar = calculateRoundedArcPath(
    layout.circleRect,
    to: progress,
    degrees: axis.degrees,
    thickness: axis.style.thickness,
  );

  final paint = Paint()..style = PaintingStyle.fill;

  if (shader != null) {
    paint.shader = shader!;
  } else if (gradient != null) {
    const rotationDifference = 270;
    final degrees = axis.degrees.clamp(10.0, 360.0);
    final rotationAngle = toRadians(rotationDifference - degrees / 2);

    paint.shader = ui.Gradient.sweep(
      layout.circleRect.center,
      gradient!.colors,
      gradient!.colorStops,
      gradient!.tileMode,
      0.0,
      toRadians(axis.degrees),
      GradientRotation(rotationAngle).transform(layout.circleRect).storage,
    );
  } else if (color != null) {
    paint.color = color!;
  }

  canvas.drawPath(progressBar, paint);
}