Fix: null labelPainter

This commit is contained in:
Victor Choueiri 2018-03-21 03:45:17 +02:00 committed by Victor Choueiri
parent ae85badc74
commit 5c371cf6fc
2 changed files with 15 additions and 13 deletions

View File

@ -243,7 +243,7 @@ class AnimatedCircularChartState extends State<AnimatedCircularChart>
size: widget.size,
painter: new AnimatedCircularChartPainter(
_tween.animate(_animation),
_labelPainter,
widget.holeLabel != null ? _labelPainter : null,
),
);
}

View File

@ -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