drawPie method

void drawPie(
  1. Canvas canvas
)

Implementation

void drawPie(Canvas canvas) {
  if (chartBeans?.isEmpty ?? true) {
    return;
  }
  Paint paint = Paint()..isAntiAlias = true;
  var rect = Rect.fromCircle(center: Offset(centerX, centerY), radius: R!);
  var realAngle = value * 2 * pi; //当前动画值对应的总角度
  for (var bean in chartBeans!) {
    var targetAngle = bean.startAngle! + bean.sweepAngle!;
    paint..color = bean.color!;
    if (targetAngle <= realAngle) {
      canvas.drawArc(rect, bean.startAngle!, bean.sweepAngle!, true, paint);
    } else if (bean.startAngle! < realAngle) {
      double sweepAngle = realAngle - bean.startAngle!;
      canvas.drawArc(rect, bean.startAngle!, sweepAngle, true, paint);
    }
  }
}