我正在尝试删除Flutter中的最后绘制的元素。只有一些示例可以删除整个草图。 removeLast()函数无法按预期运行。希望有所帮助。
class Sketcher extends CustomPainter {
final List<Offset> points;
Sketcher(this.points);
var color = Colors.black;
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = color
..strokeCap = StrokeCap.round
..strokeWidth = 4.0;
for (int i = 0; i < points.length - 1; i++) {
if (points[i] != null && points[i + 1] != null) {
canvas.drawLine(points[i], points[i + 1], paint);
}
}
}
@override
bool shouldRepaint(Sketcher oldDelegate) {
return oldDelegate.points != points;
}
}