Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class RoundedRectangleProgress extends CustomPainter {
- final double currentProgress;
- final BorderRadius borderRadius;
- final Color color;
- RoundedRectangleProgress({
- this.color = Colors.blue,
- this.borderRadius = BorderRadius.zero,
- this.currentProgress = 0,
- });
- @override
- void paint(Canvas canvas, Size size) {
- final rect = Offset.zero & size;
- //1
- final shapeBounds = Rect.fromLTRB(0, 0, size.width, size.height);
- //2
- final paint = Paint()
- ..strokeWidth = 10
- ..color = currentProgress > 288 ? Colors.redAccent : color
- ..style = PaintingStyle.stroke
- ..strokeCap = StrokeCap.square
- ..shader = SweepGradient(
- colors: [
- if (currentProgress > 288) Colors.redAccent else color,
- Colors.white,
- ],
- stops: const [1.0, 1.0],
- startAngle: 0,
- endAngle: vector.radians(currentProgress),
- transform: GradientRotation(vector.radians(-90)),
- ).createShader(rect);
- //3
- //canvas.drawRect(shapeBounds, paint);
- final borderRect =
- borderRadius.resolve(TextDirection.ltr).toRRect(shapeBounds);
- canvas.drawRRect(borderRect, paint);
- }
- @override
- bool shouldRepaint(CustomPainter oldDelegate) {
- return true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement