Search

fl_chart

import 'package:flutter/material.dart'; import 'package:fl_chart/fl_chart.dart'; class ProgressPieChart extends StatelessWidget { final double radius; final double fontSize; final Color p1Color; final double p1Value; final Color p2Color; final double p2Value; const ProgressPieChart({ required this.radius, required this.fontSize, required this.p1Color, required this.p1Value, required this.p2Color, required this.p2Value, Key? key}) : super(key: key); Widget build(BuildContext context) { return PieChart(PieChartData( sections: showingSections(), centerSpaceRadius: 0, startDegreeOffset: 270, )); } List<PieChartSectionData> showingSections() { final PieChartSectionData defaultPieChart = PieChartSectionData( // Basic Settings radius: radius, titleStyle: TextStyle( fontSize: fontSize, fontWeight: FontWeight.bold, color: Colors.white, ), ); return List.generate(2, (i) { switch (i) { case 0: return defaultPieChart.copyWith( color: p1Color, value: p1Value, title: "${p1Value.toStringAsFixed(0)}%", ); case 1: return defaultPieChart.copyWith( color: p2Color, value: p2Value, title: "${p2Value.toStringAsFixed(0)}%", ); default: throw Error(); } }); } }
Dart
복사

Reference