From 5c371cf6fc7601620e8dc5093355b13b4be71b2e Mon Sep 17 00:00:00 2001 From: Victor Choueiri Date: Wed, 21 Mar 2018 03:45:17 +0200 Subject: [PATCH] Fix: null labelPainter --- lib/src/animated_circular_chart.dart | 2 +- lib/src/painter.dart | 26 ++++++++++++++------------ 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/lib/src/animated_circular_chart.dart b/lib/src/animated_circular_chart.dart index 7679d40..47cef1f 100644 --- a/lib/src/animated_circular_chart.dart +++ b/lib/src/animated_circular_chart.dart @@ -243,7 +243,7 @@ class AnimatedCircularChartState extends State size: widget.size, painter: new AnimatedCircularChartPainter( _tween.animate(_animation), - _labelPainter, + widget.holeLabel != null ? _labelPainter : null, ), ); } diff --git a/lib/src/painter.dart b/lib/src/painter.dart index d6ef54c..fa6d971 100644 --- a/lib/src/painter.dart +++ b/lib/src/painter.dart @@ -14,12 +14,7 @@ class AnimatedCircularChartPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { - labelPainter.paint( - canvas, - new Offset( - size.width / 2 - labelPainter.width / 2, - size.height / 2 - labelPainter.height / 2, - )); + _paintLabel(canvas, size, labelPainter); _paintChart(canvas, size, animation.value); } @@ -35,12 +30,7 @@ class CircularChartPainter extends CustomPainter { @override void paint(Canvas canvas, Size size) { - labelPainter.paint( - canvas, - new Offset( - size.width / 2 - labelPainter.width / 2, - size.height / 2 - labelPainter.height / 2, - )); + _paintLabel(canvas, size, labelPainter); _paintChart(canvas, size, chart); } @@ -50,6 +40,18 @@ class CircularChartPainter extends CustomPainter { const double _kRadiansPerDegree = Math.pi / 180; +void _paintLabel(Canvas canvas, Size size, TextPainter labelPainter) { + if (labelPainter != null) { + labelPainter.paint( + canvas, + new Offset( + size.width / 2 - labelPainter.width / 2, + size.height / 2 - labelPainter.height / 2, + ), + ); + } +} + void _paintChart(Canvas canvas, Size size, CircularChart chart) { final Paint segmentPaint = new Paint() ..style = chart.chartType == CircularChartType.Radial