2021-11-22 11:49:52 +03:00
|
|
|
import 'dart:math';
|
|
|
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class ProgressCircle extends StatelessWidget {
|
|
|
|
final Color color;
|
|
|
|
final double progress;
|
2022-05-12 10:56:55 +03:00
|
|
|
const ProgressCircle(this.color, this.progress, {super.key});
|
2021-11-22 11:49:52 +03:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CustomPaint(
|
|
|
|
painter: _CirclePainter(color, progress),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _CirclePainter extends CustomPainter {
|
|
|
|
final Color color;
|
|
|
|
final double progress;
|
|
|
|
_CirclePainter(this.color, this.progress);
|
|
|
|
|
|
|
|
@override
|
|
|
|
void paint(Canvas canvas, Size size) {
|
|
|
|
var radius = min(size.width, size.height) / 2;
|
|
|
|
canvas.drawArc(
|
|
|
|
Rect.fromCircle(center: Offset(radius, radius), radius: radius),
|
|
|
|
-pi / 2,
|
|
|
|
-progress * 2 * pi,
|
|
|
|
true,
|
|
|
|
Paint()..color = color,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
bool shouldRepaint(_CirclePainter oldDelegate) {
|
|
|
|
return oldDelegate.progress != progress || oldDelegate.color != color;
|
|
|
|
}
|
|
|
|
}
|