Flutter Custom Painter 在点击/滚动时消失

标签 flutter

我有一个自定义画家:

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, channel 稳定。

最佳答案

经过一番调试,我意识到这是 Flutter 本身造成的。从稳定的 v1 channel 切换到主 channel (讽刺的是)解决了这个问题。

关于Flutter Custom Painter 在点击/滚动时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53928729/

相关文章:

android - flutter 中的FAB在其他小部件后面

function - 输入长度和按钮点击的问题

flutter - Flutter:尽管用户已在Firebase Auth中注册,但一次又一次发送OTP

ios - 升级我的 flutter 版本后无法构建 iOS 应用程序

android - Flutter - 如何更改文本字段弹出菜单的样式?

dart - 如何在 flutter 中返回流中的对象列表

firebase - 如何正确将DateTime保存到Cloud Firestore

dart - 在Flutter中用省略号显示段落

flutter - 如何使 GestureDetector 捕获堆栈内的点击?

dart - 如何在 Flutter 中制作 ArcProgress Bar?