-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Null check missing in code: Line chart with hidden legends throws exception #2208
Comments
Hi, We have checked the mentioned scenario and tried to replicate the reported it in Charts widget with version 28.1.35 by Regards, |
Modified your code to reproduce the issue. Have a look.
|
Hi @PT10 , We have resolved the issue where a null value was returned when disabling the legend of the trendline at load time in the SfCartesianChart. The fix has been moved to the upcoming weekly patch release, scheduled for December 24, 2024. We appreciate your patience and understanding until then. Regards, |
Bug description
There is a clear issue in the code. When "isVisibleInLegend" is false, null is returned. And then there is no null check in the caller.
chart_series.dart
Here a null check is required on items before calling items!.addAll.
Following is the method from base class which this code calls (super.buildLegendItems) and it can return null.
Steps to reproduce
Any line chart which a single series and show legend flag on.
Code sample
Code sample
@OverRide
List? buildLegendItems(int index) {
final List? items = super.buildLegendItems(index);
if (trendlineContainer != null) {
items!.addAll(trendlineContainer!.buildLegendItems(index, this)!);
}
return items;
}
@OverRide
List? buildLegendItems(int index) {
if (isVisibleInLegend) {
final LegendItem legendItem = ChartLegendItem(
text: legendItemText ?? name,
iconType: toLegendShapeMarkerType(legendIconType, this),
iconColor: legendIconColor(),
iconBorderColor: legendIconBorderColor(),
iconBorderWidth: legendIconBorderWidth(),
series: this,
seriesIndex: index,
pointIndex: 0,
isToggled: _isToggled(),
shader: legendIconShader(),
overlayMarkerType: markerSettings.isVisible
? toShapeMarkerType(markerSettings.shape)
: null,
imageProvider: legendIconType == LegendIconType.image
? parent?.legend?.image
: null,
onTap: handleLegendItemTapped,
onRender: _handleLegendItemCreated,
);
return [legendItem];
} else {
return null;
}
}
Screenshots or Video
Screenshots / Video demonstration
[Upload media here]
Stack Traces
Stack Traces
On which target platforms have you observed this bug?
Web
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: