devtools icon indicating copy to clipboard operation
devtools copied to clipboard

[Memory Panel] Fix `canvasChartWidth` has not been initialized error when changing the zoom duration

Open elliette opened this issue 1 month ago • 0 comments

Fixes https://github.com/flutter/devtools/issues/8187

Fixes the "canvasChartWidth has not been initialized" error which can occur when setting the zoom duration in the Memory Panel.


Explanation

Setting the zoomDuration for a chart triggers a call to canvasChartWidth, which is only set after a chart has been painted:

In paint():

https://github.com/flutter/devtools/blob/2f73978a8924e43d2cae2a696bccad3712cbcc9a/packages/devtools_app/lib/src/shared/charts/chart.dart#L158-L161

In computeChartArea(): https://github.com/flutter/devtools/blob/2f73978a8924e43d2cae2a696bccad3712cbcc9a/packages/devtools_app/lib/src/shared/charts/chart_controller.dart#L409-L411

However, not all charts are painted by default. The Android chart is only conditionally painted:

https://github.com/flutter/devtools/blob/2f73978a8924e43d2cae2a696bccad3712cbcc9a/packages/devtools_app/lib/src/screens/memory/panes/chart/widgets/chart_pane.dart#L166-L170

Therefore, the fix here is to only set the zoomDuration for the Android chart if it's visible.

elliette avatar Dec 11 '25 18:12 elliette