我有一个CustomPainter:
class _Painter extends CustomPainter {
_Painter({
@required this.animation,
this.strokeWidth,
@required this.valuePercentage,
@required this.color,
}) : super(repaint: animation);
final Animation<double> animation;
final double strokeWidth;
final double valuePercentage;
final Color color;
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = Colors.black12
..strokeWidth = strokeWidth ?? 5.0
..strokeCap = StrokeCap.round
..style = PaintingStyle.stroke;
canvas.drawCircle(size.center(Offset.zero), size.width / 2.0, paint);
paint.color = color;
double progressRadians =
(valuePercentage != 0 ? valuePercentage : 1.0) * 2 * pi;
canvas.drawArc(Offset.zero & size, pi * 1.5, progressRadians, false, paint);
}
@override
bool shouldRepaint(_Painter other) {
return valuePercentage != other.valuePercentage;
}
}
像这样在StatelessWidget中使用:
@override
Widget build(BuildContext context) {
return Stack(
children: <Widget>[
SizedBox(
height: radius * 2,
width: radius * 2,
child: Center(
child: CustomPaint(
size: Size((radius - 3) * 2, (radius - 3) * 2),
painter: _Painter(
animation: animationController,
strokeWidth: strokeWidth,
valuePercentage: _valuePercentage,
color: color,
),
),
),
),
// ...
],
);
}
结果:
现在,这发生了:
Flutter v1.0.0,稳定的频道。
答案 0 :(得分:0)
经过更多的调试,我意识到这是由Flutter本身引起的。从稳定的v1频道切换到主频道(具有讽刺意味的是)解决了该问题。