Flutter 点击/滚动时,颤振自定义画师消失

Flutter 点击/滚动时,颤振自定义画师消失,flutter,Flutter,我有一位画家: class _Painter extends CustomPainter { _Painter({ @required this.animation, this.strokeWidth, @required this.valuePercentage, @required this.color, }) : super(repaint: animation); final Animation<double> animation

我有一位画家:

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;
  }
}
class\u画师扩展自定义画师{
_油漆工({
@需要这个动画,
这是一个.strokeWidth,
@所需的此值百分比,
@需要这个颜色,
}):super(重新绘制:动画);
最终动画;
最终双冲程宽度;
最终双倍价值百分比;
最终颜色;
@凌驾
空白油漆(帆布,尺寸){
油漆油漆=油漆()
…颜色=颜色。黑色
..冲程宽度=冲程宽度±5.0
..strokeCap=strokeCap.round
..风格=绘画风格.笔划;
画布.画圈(大小.中心(偏移.零),大小.宽度/2.0,绘制);
paint.color=颜色;
双弧度=
(valuePercentage!=0?valuePercentage:1.0)*2*pi;
画布绘制弧(偏移量、零点和大小、pi*1.5、弧度、假、油漆);
}
@凌驾
布尔应该重新油漆(其他油漆工){
返回值百分比!=其他.valuePercentage;
}
}
在无状态窗口小部件中如此使用:

@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,
              ),
            ),
          ),
        ),
        // ...
      ],
    );
  }
@覆盖
小部件构建(构建上下文){
返回堆栈(
儿童:[
大小盒子(
高度:半径*2,
宽度:半径*2,
儿童:中心(
孩子:定制油漆(
尺寸:尺寸((半径-3)*2,(半径-3)*2),
画家:画家(
动画:animationController,
strokeWidth:strokeWidth,
valuePercentage:\u valuePercentage,
颜色:颜色,
),
),
),
),
// ...
],
);
}
结果是:

现在,这种情况发生了:


颤振v1.0.0,稳定通道。

经过一点调试后,我意识到这是颤振本身造成的。从稳定的v1频道切换到主频道(讽刺的是)解决了这个问题。

你需要什么
animation:animationController
?您没有以任何方式在
\u Painter
类中使用它