yubioath-flutter/lib/widgets/progress_circle.dart
2022-05-12 12:05:18 +02:00

40 lines
928 B
Dart
Executable File

import 'dart:math';
import 'package:flutter/material.dart';
class ProgressCircle extends StatelessWidget {
final Color color;
final double progress;
const ProgressCircle(this.color, this.progress, {super.key});
@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;
}
}