From 68cf161f2623cedda2bf1b51bef758cf62beb812 Mon Sep 17 00:00:00 2001 From: imaNNeoFighT Date: Fri, 15 Dec 2023 22:11:53 +0100 Subject: [PATCH] Fix pieChart drawing single section on iPhone, #1515 --- CHANGELOG.md | 1 + .../chart/pie_chart/pie_chart_painter.dart | 27 ++++++++++++++----- 2 files changed, 22 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4b739482a..7a80f51e8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -24,6 +24,7 @@ ScatterSpot( ), ``` * **BUGFIX** (by @imaNNeo) Fix barChart tooltip for values below or above the 0 point, #1462 +* **BUGFIX** (by @imaNNeo) Fix pieChart drawing single section on iPhone, #1515 ## 0.65.0 * **FEATURE** (by @Dartek12) Added gradient to [FlLine](https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/base_chart.md#FlLine), #1197 diff --git a/lib/src/chart/pie_chart/pie_chart_painter.dart b/lib/src/chart/pie_chart/pie_chart_painter.dart index 8f73cdced..ef1081a48 100644 --- a/lib/src/chart/pie_chart/pie_chart_painter.dart +++ b/lib/src/chart/pie_chart/pie_chart_painter.dart @@ -21,11 +21,15 @@ class PieChartPainter extends BaseChartPainter { PieChartPainter() : super() { _sectionPaint = Paint()..style = PaintingStyle.stroke; + _sectionSaveLayerPaint = Paint(); + _sectionStrokePaint = Paint()..style = PaintingStyle.stroke; _centerSpacePaint = Paint()..style = PaintingStyle.fill; } + late Paint _sectionPaint; + late Paint _sectionSaveLayerPaint; late Paint _sectionStrokePaint; late Paint _centerSpacePaint; @@ -100,13 +104,24 @@ class PieChartPainter extends BaseChartPainter { if (sectionDegree == 360) { _sectionPaint ..color = section.color - ..strokeWidth = section.radius - ..style = PaintingStyle.stroke; - canvasWrapper.drawCircle( - center, - centerRadius + section.radius / 2, - _sectionPaint, + ..style = PaintingStyle.fill; + final bounds = Rect.fromCircle( + center: center, + radius: centerRadius + section.radius, ); + canvasWrapper + ..saveLayer(bounds, _sectionSaveLayerPaint) + ..drawCircle( + center, + centerRadius + section.radius, + _sectionPaint..blendMode = BlendMode.srcOver, + ) + ..drawCircle( + center, + centerRadius, + _sectionPaint..blendMode = BlendMode.srcOut, + ) + ..restore(); if (section.borderSide.width != 0.0 && section.borderSide.color.opacity != 0.0) { _sectionStrokePaint