Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import 'dart:math';
import 'package:flutter/material.dart';
class CircleProgress extends CustomPainter {
double value;
bool isTemp;
CircleProgress(this.value, this.isTemp);
@override
bool shouldRepaint(CustomPainter oldDelegate) {
return true;
}
@override
void paint(Canvas canvas, Size size) {
int maximumValue =
isTemp ? 50 : 100; // Temp's max is 50, Humidity's max is 100
Paint outerCircle = Paint()
..strokeWidth = 14
..color = Colors.deepPurple
..style = PaintingStyle.stroke;
Paint tempArc = Paint()
..strokeWidth = 14
..color = Color(0xFFB2BCCC)
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
Paint humidityArc = Paint()
..strokeWidth = 14
..color = Color(0xFFB2BCCC)
..style = PaintingStyle.stroke
..strokeCap = StrokeCap.round;
Offset center = Offset(size.width / 2, size.height / 2);
double radius = min(size.width / 2, size.height / 2) - 14;
canvas.drawCircle(center, radius, outerCircle);
double angle = 2 * pi * (value / maximumValue);
canvas.drawArc(Rect.fromCircle(center: center, radius: radius), -pi / 2,
angle, false, isTemp ? tempArc : humidityArc);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment