Step 1 / 5
CustomPaint hosts a painter
CustomPaint is a widget that gives a CustomPainter a canvas of a given size.
Draw your own graphics, like charts, rings and clocks, on a Canvas with CustomPainter.
1class RingPainter extends CustomPainter {2 RingPainter(this.progress);3 final double progress;45 @override6 void paint(Canvas canvas, Size size) {7 final center = size.center(Offset.zero);8 final radius = size.shortestSide / 2 - 8;9 final paint = Paint()10 ..style = PaintingStyle.stroke11 ..strokeWidth = 1212 ..strokeCap = StrokeCap.round13 ..color = Colors.blue;1415 canvas.drawArc(16 Rect.fromCircle(center: center, radius: radius),17 -pi / 2, // start at 12 o'clock18 2 * pi * progress, // sweep19 false,20 paint,21 );22 }2324 @override25 bool shouldRepaint(RingPainter old) => old.progress != progress;26}2728CustomPaint(size: const Size(120, 120), painter: RingPainter(0.7))
shouldRepaint(old) =>
old.progress != progress;CustomPaint is a widget that gives a CustomPainter a canvas of a given size.