gpt4 book ai didi

dart - 如何在延迟几秒钟后在 Flutter 的 Canvas 上连续绘画

转载 作者:IT王子 更新时间:2023-10-29 06:44:21 26 4
gpt4 key购买 nike

我定义了一组偏移量。我只想在延迟后在 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 中有 Offsets。请帮忙。

最佳答案

必须使用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

关于dart - 如何在延迟几秒钟后在 Flutter 的 Canvas 上连续绘画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49726819/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com