我定义了一组偏移。我想要的是在延迟后在画布上绘制这些偏移。这是为了向用户显示绘图的进度。我怎么能这样做。这是我的代码。但它在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;
}
}
PathData中有偏移量。请帮忙。
答案 0 :(得分:1)
必须使用AnimationController。在阅读了以下两部分教程后,我能够做到这一点。
https://medium.com/flutter-io/zero-to-one-with-flutter-43b13fd7b354
https://medium.com/flutter-io/zero-to-one-with-flutter-part-two-5aa2f06655cb