我有一组已定义的偏移量。我只想在延迟后在画布上绘制这些偏移量,以向用户展示绘图进度。我该如何实现相同的效果?以下是我的代码。但它会在drawPath行报错,提示“对象已被处理”。
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;
}
}
路径数据中包含偏移量,请帮忙。