import 'package:flutter/material.dart'; class CircleProgressBarPainter extends CustomPainter { var _paintBckGround; var _paintFore; final _strokeWidth; final _backgroundColor; final _foreColor; final _startAngle; final _sweepAngle; final _endAngle; CircleProgressBarPainter(this._backgroundColor, this._foreColor, this._startAngle, this._sweepAngle, this._endAngle, this._strokeWidth) { _paintBckGround = Paint() ..color = _backgroundColor ..isAntiAlias = true ..strokeCap = StrokeCap.round ..strokeWidth = _strokeWidth ..style = PaintingStyle.stroke; final Gradient gradient = SweepGradient( endAngle: _endAngle, colors: [ _foreColor, _backgroundColor, ], ); final Rect arcRect = Rect.fromCircle(center: Offset(0, 0), radius: _endAngle); _paintFore = Paint() ..color = _foreColor ..isAntiAlias = true ..strokeWidth = _strokeWidth ..strokeCap = StrokeCap.round ..shader=gradient.createShader(arcRect) ..style = PaintingStyle.stroke; } @override void paint(Canvas canvas, Size size) { var radius = size.width > size.height ? size.width / 2 : size.height / 2; Rect rect = Rect.fromCircle(center: Offset(radius, radius), radius: radius); canvas.drawCircle(Offset(radius, radius), radius, _paintBckGround); canvas.drawArc(rect, _startAngle / 180 * 3.14, _sweepAngle / 180 * 3.14, false, _paintFore); } @override bool shouldRepaint(CustomPainter oldDelegate) { return _sweepAngle != _endAngle; } }