我定义了一组偏移。我只想在延迟后在 Canvas 上绘制这些偏移。这是为了向用户显示绘图进度。我该怎么做。这是我的代码。但是它会错误地在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中具有偏移量。请帮忙。
最佳答案
必须使用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