diff --git a/lib/src/chart/pie_chart/pie_chart_data.dart b/lib/src/chart/pie_chart/pie_chart_data.dart index 37e70e7b4..112d746a6 100644 --- a/lib/src/chart/pie_chart/pie_chart_data.dart +++ b/lib/src/chart/pie_chart/pie_chart_data.dart @@ -31,8 +31,7 @@ class PieChartData extends BaseChartData with EquatableMixin { PieTouchData? pieTouchData, FlBorderData? borderData, bool? titleSunbeamLayout, - }) : sections = sections?.where((element) => element.value != 0).toList() ?? - const [], + }) : sections = sections ?? const [], centerSpaceRadius = centerSpaceRadius ?? double.infinity, centerSpaceColor = centerSpaceColor ?? Colors.transparent, sectionsSpace = sectionsSpace ?? 2, diff --git a/lib/src/chart/pie_chart/pie_chart_painter.dart b/lib/src/chart/pie_chart/pie_chart_painter.dart index 9517c72ec..c1a31d92c 100644 --- a/lib/src/chart/pie_chart/pie_chart_painter.dart +++ b/lib/src/chart/pie_chart/pie_chart_painter.dart @@ -60,6 +60,10 @@ class PieChartPainter extends BaseChartPainter { List sections, double sumValue, ) { + if (sumValue == 0) { + return List.filled(sections.length, 0); + } + return sections.map((section) { return 360 * (section.value / sumValue); }).toList(); @@ -100,6 +104,9 @@ class PieChartPainter extends BaseChartPainter { for (var i = 0; i < data.sections.length; i++) { final section = data.sections[i]; + if (section.value == 0) { + continue; + } final sectionDegree = sectionsAngle[i]; if (sectionDegree == 360) { @@ -358,6 +365,9 @@ class PieChartPainter extends BaseChartPainter { for (var i = 0; i < data.sections.length; i++) { final section = data.sections[i]; + if (section.value == 0) { + continue; + } final startAngle = tempAngle; final sweepAngle = 360 * (section.value / data.sumValue); final sectionCenterAngle = startAngle + (sweepAngle / 2); @@ -453,6 +463,7 @@ class PieChartPainter extends BaseChartPainter { var tempAngle = 0.0; for (var i = 0; i < data.sections.length; i++) { final section = data.sections[i]; + var sectionAngle = sectionsAngle[i]; tempAngle %= 360; diff --git a/lib/src/chart/pie_chart/pie_chart_renderer.dart b/lib/src/chart/pie_chart/pie_chart_renderer.dart index ef001a477..ff29d5854 100644 --- a/lib/src/chart/pie_chart/pie_chart_renderer.dart +++ b/lib/src/chart/pie_chart/pie_chart_renderer.dart @@ -144,7 +144,20 @@ class RenderPieChart extends RenderBaseChart paintHolder, ); canvas.restore(); - defaultPaint(context, offset); + badgeWidgetPaint(context, offset); + } + + void badgeWidgetPaint(PaintingContext context, Offset offset) { + RenderObject? child = firstChild; + var counter = 0; + while (child != null) { + final childParentData = child.parentData! as MultiChildLayoutParentData; + if (data.sections[counter].value > 0) { + context.paintChild(child, childParentData.offset + offset); + } + child = childParentData.nextSibling; + counter++; + } } @override