paintWithProgress method

  1. @override
void paintWithProgress(
  1. Canvas canvas,
  2. Size size,
  3. Paint paint,
  4. double p,
)
override

Implementation

@override
void paintWithProgress(Canvas canvas, Size size, Paint paint, double p) {
  double width = size.width;
  double height = size.height;

  // the best ratio is width: height => 3 : 2
  Path path = Path();
  double shortLineX = 0;
  double shortLineY = height / 2;
  double shortLineW = width / 3;

  path.moveTo(shortLineX, shortLineY);

  double ratio = p * 2;
  double ratioShort = ratio <= 1 ? ratio : 1, ratioLong = ratio >= 1 ? ratio - 1 : 0;

  // draw short line & long line
  path.lineTo(shortLineX + (shortLineW - shortLineX) * ratioShort, shortLineY + (height - shortLineY) * ratioShort);
  if (ratioLong != 0) {
    path.lineTo(shortLineW + (width - shortLineW) * ratioLong, height - ratioLong * height);
  }
  canvas.drawPath(path, paint);
}