Skip to content

Instantly share code, notes, and snippets.

@Indy9000
Created May 31, 2021 16:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Indy9000/47490fb274dd8c579f435d6748fd9707 to your computer and use it in GitHub Desktop.
Save Indy9000/47490fb274dd8c579f435d6748fd9707 to your computer and use it in GitHub Desktop.
animated-donut-chart-03
class DonutChartPainter extends CustomPainter {
final List<DataItem> dataset;
DonutChartPainter(this.dataset);
@override
void paint(Canvas canvas, Size size) {
final c = Offset(size.width / 2.0, size.height / 2.0);
final radius = size.width * 0.9;
final rect = Rect.fromCenter(center: c, width: radius, height: radius);
final fullAngle = 360.0;
var startAngle = 0.0;
//draw sectors
dataset.forEach((di) {
final sweepAngle = di.value * fullAngle * pi / 180.0;
drawSector(canvas, di, rect, startAngle, sweepAngle);
drawLabels(canvas, c, radius, startAngle, sweepAngle, di.label);
startAngle += sweepAngle;
});
// draw the middle
canvas.drawCircle(c, radius * 0.3, midPaint);
// draw title
drawTextCentered(canvas, c, "Favourite\nMovie\nGenres",
textFieldTextBigStyle, radius * 0.6, (Size sz) {});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment