0

I have real-time data values painted as a graph from left to right in flutter. Its a lot of source data but very simple: Vertical lines canvas.drawLine(from here, to here) from a realtime list of doubles drawing from left to right across the screen.

After the screen is full I want to completely discard the painted information and draw again from left to right.

I've 'functionally' accomplished this by drawing the graph then drawing a black box over the top of the canvas and drawing again however this is totally non-performant. Within a minute performance degrades and memory starts swapping out to cache. The information is obviously being kept.

I'd appreciate specific advice on the following please guys:

  • Best practice for clearing a canvas from inside a custom paint where the actual information gets disposed and the overall cache/memory usage of the canvas thus remains bounded.
  • If this isn't possible, any of the most performant work arounds you can think of.
  • Have you tried this? It's the same question. https://stackoverflow.com/questions/59626727/how-to-erase-clip-from-canvas-custompaint – heathscliff Nov 02 '21 at 02:50
  • Not quite the same but I've looked at those options and they don't work. Adapting them actually fails due to some peculiar conditional logic behaviour inside custompaint. Specifically the painter is 'for in' loop painting from a list of ints. Calling conditional logic inside the painter when the x value gets to the right side of the screen fails because the drawRect erasure totally ignores the condition its nested inside and erases the screen no matter what. It actually assumes the end value for x instantly. Seems some look ahead/pre-render functionality is bugged by accident or design. – Mark Bowler Nov 02 '21 at 10:22

0 Answers0