syncfusion/flutter-widgets

[syncfusion_flutter_charts] crash with null xAxis

Closed this issue · 3 comments

Bug description

From versions 30.1.39 (possibly earlier) to 30.2.4 (latest), we see set xAxis(RenderChartAxis? value) (axis.dart) receiving null, which violates an assertion in the setter.

The following assertion was thrown while rebuilding dirty elements:
'package:syncfusion_flutter_charts/src/charts/axis/axis.dart': Failed assertion: line 3855 pos 12: 'value != null': is not true.

https://github.com/syncfusion/flutter-widgets/blame/master/packages/syncfusion_flutter_charts/lib/src/charts/axis/axis.dart#L3855

  • When we comment out the failing assertion, the stack shows a few more places where the ! operator is incorrectly applied to a null value.
The following _TypeError was thrown during paint():
Null check operator used on a null value

The relevant error-causing widget was:  [REDACTED]
When the exception was thrown, this was the stack: 
#0      LineSeriesRenderer.onPaint (package:syncfusion_flutter_charts/src/charts/series/line_series.dart:148:24)

https://github.com/syncfusion/flutter-widgets/blame/master/packages/syncfusion_flutter_charts/lib/src/charts/series/line_series.dart#L148

https://github.com/syncfusion/flutter-widgets/blame/master/packages/syncfusion_flutter_charts/lib/src/charts/series/chart_series.dart#L5590

  • Simply replacing the ! with ? seems to resolve our issue.

I believe this is a bug in the library -- since the type RenderChartAxis? allows null, it should be handled by all callers which read the xAxis property.

Please let me know if you'd like me to submit a PR which fixes the issue for us.

Steps to reproduce

Unfortunately, I cannot provide steps to reproduce.

Code sample

Unfortunately, I cannot provide a minimal code sample.

Screenshots or Video

(no screenshots/video)

Stack Traces

(see above)

On which target platforms have you observed this bug?

Windows

Flutter Doctor output

Doctor output
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.32.8, on LMDE 6 (faye) 6.12.33+deb12-amd64, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
[✓] Chrome - develop for the web
[✓] Linux toolchain - develop for Linux desktop
[✓] Android Studio (version 2025.1.2)
[✓] IntelliJ IDEA Ultimate Edition (version 2025.1)
[✓] Connected device (2 available)
[✓] Network resources

Hi @mockturtl ,

We have analyzed the reported case and found that the case occurs when xAxisName or yAxisName is assigned in the series without defining a corresponding axis with the same name in the chart, which leads to a null exception during rendering.

As per the current implementation, any axis name used in the series must be defined either in primaryXAxis/primaryYAxis with a matching name or added to the axes collection.

For example, if the series uses xAxisName : xName and yAxisName : yName, the chart should include DateTimeAxis(name: xName) and NumericAxis(name: yName) either directly or within the axes collection.

Regards,
Praveen Balu.

@BPraveenBalu Thank you! Ensuring every XyDataSeries.xAxisName has a matching entry in SfCartesianChart.axes pointed us to a helpful workaround.

I still hope the discrepancy between RenderChartAxis? value and assert(value != null) can be fixed in a future release.

Any release notes you can provide in the CHANGELOG are very useful for us. When a new release appears on pub.dev, it's difficult to know what changed between versions -- for example, v30.2.5 appeared yesterday, but the most recent commit in this repo (134e1c8) was over a month ago.

As a business customer, we're considering alternative solutions to save time in regression testing. We hope the company will consider devoting more resources to the Flutter implementation. 💙

Hi @mockturtl

Thanks for your feedback! As per our previous update the assertion is expected behavior when axis names in the series aren’t defined in the chart. Defining matching axes resolves this.

We’d also like to let you know that we will publish weekly patch releases every Tuesday, and the changelog is updated accordingly with all changes included in each release.

You can find the changelog here: syncfusion_flutter_charts changelog | Flutter package.

Regards,
Praveen Balu.