Skip to content

Instantly share code, notes, and snippets.

@miguelpruivo
Created September 3, 2019 00:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miguelpruivo/c1d0a3f49bb954c1f74f4b06c323ff7f to your computer and use it in GitHub Desktop.
Save miguelpruivo/c1d0a3f49bb954c1f74f4b06c323ff7f to your computer and use it in GitHub Desktop.
Circular progress painter (wip)
class ProgressPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
double percent = 85;
Paint p = Paint()
..color = Colors.white24
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round
..strokeWidth = 4.0;
final double inRadians = (pi * 2) / 100;
Path path = Path();
path.moveTo(size.width / 2, size.height / 2);
path.relativeMoveTo(-28.0, 18.0);
path.relativeLineTo(-19.0, 18.0);
path.addArc(Rect.fromCircle(center: Offset(size.width / 2, size.height / 2), radius: size.width / 2), 0.8 * pi, 95 * inRadians);
path.relativeLineTo(20.0, -20.0);
canvas.drawPath(path, p);
p.color = Colors.white;
Path p2 = Path();
p2.moveTo(size.width / 2, size.height / 2);
p2.relativeMoveTo(-28.0, 18.0);
p2.relativeLineTo((min(percent, 5) * -19.0) / 5, (min(percent, 5) * 18.0) / 5);
if (percent > 5) {
p2.addArc(Rect.fromCircle(center: Offset(size.width / 2, size.height / 2), radius: size.width / 2), 0.8 * pi, min(percent, 95) * inRadians);
}
if (percent > 95) {
p2.relativeLineTo((95 - percent).abs() * 20.0 / 5, (95 - percent).abs() * -20.0 / 5);
}
canvas.drawPath(p2, p);
}
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment