Flutter - can't access to previous PaintingContext in RenderObject paint function

Viewed 29

I have a LeafRenderObjectWidget and want to update my view according to the new widget parameters. for example, I have drawn a line and wish to update the line using scale and don't want to paint it again on the next build. the problem is in the paint function of RenderObject I have access to PaintingContext but it is not the previous one. so I can't use context.canvas.save() and restore it again in the paint function.

1 Answers

When creating RenderObjects from scratch it's easy to get carried away, but my advice is to not fear repainting. When you call methods on a canvas all it's doing is adding commands to a list that eventually get sent to the raster thread, no actual rendering work is being done here.

It sounds like you are confused on the purpose of canvas.save and canvas.restore. These methods do not save what you painted to the canvas, they only touch the paint transform set by scale, skew, transform and translate.

Related