Dart 如何在延迟几秒钟后在画布上连续绘制

Dart 如何在延迟几秒钟后在画布上连续绘制,dart,flutter,Dart,Flutter,我定义了一组偏移。我只想在一段延迟后在画布上绘制这些偏移。这是为了向用户显示绘图的进度。我怎么能这样做呢。这是我的密码。但它在绘图路径线处错误地指出“对象已被处置” class ReplayPainter extends CustomPainter { List<PathData> strokes = new List<PathData>(); ReplayPainter(this.strokes); @override void paint(Canv

我定义了一组偏移。我只想在一段延迟后在画布上绘制这些偏移。这是为了向用户显示绘图的进度。我怎么能这样做呢。这是我的密码。但它在绘图路径线处错误地指出“对象已被处置”

class ReplayPainter extends CustomPainter {
  List<PathData> strokes = new List<PathData>();

  ReplayPainter(this.strokes);

  @override
  void paint(Canvas canvas, Size size) {
    print(strokes.length);
    for (PathData stroke in strokes) {
      Paint strokePaint = new Paint();
      strokePaint.strokeWidth = stroke.strokeWidth;
      strokePaint.style = PaintingStyle.stroke;
      strokePaint.strokeJoin = StrokeJoin.round;
      strokePaint.strokeCap = StrokeCap.round;
      strokePaint.color = stroke.strokeColor;

      Path strokePath = new Path();
      strokePath.addPolygon(stroke.offsets, false);
      Timer _timer = new Timer(const Duration(milliseconds: 100), () {
        canvas.drawPath(strokePath, strokePaint);
      });
    }
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return false;
  }

}
class ReplayPaint扩展了CustomPainter{
列表笔划=新列表();
重画者(此为笔划);
@凌驾
空心油漆(帆布,尺寸){
打印(笔画、长度);
for(笔划中的PathData笔划){
绘制strokePaint=新绘制();
strokePaint.strokeWidth=stroke.strokeWidth;
strokePaint.style=PaintingStyle.stroke;
strokePaint.strokeJoin=strokeJoin.round;
strokePaint.strokeCap=strokeCap.round;
strokePaint.color=stroke.strokeColor;
路径strokePath=新路径();
strokePath.addPolygon(stroke.offset,false);
计时器_Timer=新计时器(常量持续时间(毫秒:100),(){
画布绘制路径(strokePath、strokePaint);
});
}
}
@凌驾
bool应重新绘制(自定义代理){
返回false;
}
}

PathData中包含偏移量。请帮忙

必须使用AnimationController。在阅读了下面两部分的教程之后,我能够做到这一点