Skip to content

Conversation

@elliette
Copy link
Member

Fixes #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():

if (size != chartController.size) {
chartController.size = size;
chartController.computeChartArea();
}

In computeChartArea():

// Compute max number of ticks visible on X-Axis.
visibleXAxisTicks = (width / tickWidth).truncate();
canvasChartWidth = visibleXAxisTicks.toDouble() * tickWidth;

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

if (widget.chart.isAndroidChartVisible.value)
SizedBox(
height: defaultChartHeight,
child: MemoryChart(widget.chart.android, sampleAdded),
),

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

@elliette elliette requested a review from a team as a code owner December 11, 2025 18:59
@elliette elliette requested review from srawlins and removed request for bkonyi and kenzieschmoll December 15, 2025 17:42
@elliette elliette merged commit 8005ab7 into flutter:master Dec 15, 2025
35 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

"'canvasChartWidth' has not been initialized" error when setting time-range in Memory tab

2 participants