syncfusion / flutter-widgets

Syncfusion Flutter widgets libraries include high quality UI widgets and file-format packages to help you create rich, high-quality applications for iOS, Android, and web from a single code base.
1.44k stars 672 forks source link

Errors while adding values to a StackedColumnSeries during runtime with updateDataSource #1817

Closed DrNiels closed 5 days ago

DrNiels commented 1 month ago

Bug description

While adding values to a StackedColumnSeries and confirming them via controller.updateDataSource, sometimes an error is thrown. I could not observe when it does and when it does not, but the following example throws them a lot. I use the version 25.1.40 of syncfusion_flutter_charts.

Steps to reproduce

Load the code sample and pan to the left.

Code sample

Code sample ```dart import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; void main() async { runApp( MaterialApp( home: TestChart(), ), ); } class TestChart extends StatefulWidget { _TestChartState createState() => _TestChartState(); } class _TestChartState extends State { // Just ensure that the list is not initially empty List currentData = [ Offset(DateTime(2024, 4, 3).millisecondsSinceEpoch.toDouble(), 5), ]; ChartSeriesController? controller; @override Widget build(BuildContext context) { return SfCartesianChart( series: [ StackedColumnSeries( xValueMapper: (data, _) => DateTime.fromMillisecondsSinceEpoch(data.dx.round()), yValueMapper: (data, _) => data.dy, dataSource: currentData, onRendererCreated: (ChartSeriesController controller) { this.controller = controller; }, ), ], primaryYAxis: NumericAxis( minimum: 0, maximum: 20, ), primaryXAxis: DateTimeAxis( name: 'xAxis', minimum: DateTime(2020), maximum: DateTime(2025), initialVisibleMinimum: DateTime(2024, 4, 3), initialVisibleMaximum: DateTime(2024, 4, 14), intervalType: DateTimeIntervalType.days, ), zoomPanBehavior: ZoomPanBehavior( enablePanning: true, zoomMode: ZoomMode.x, ), onActualRangeChanged: (ActualRangeChangedArgs args) { if (args.axisName != 'xAxis') { return; } WidgetsBinding.instance.addPostFrameCallback((Duration duration) { setState(() { updateData( start: DateTime.fromMillisecondsSinceEpoch(args.visibleMin.round()), end: DateTime.fromMillisecondsSinceEpoch(args.visibleMax.round()), ); }); }); }, ); } void updateData({ required DateTime start, required DateTime end, }) { while (start.isBefore(_doubleToDateTime(this.currentData.first.dx))) { this.currentData.insert( 0, Offset( _doubleToDateTime(this.currentData.first.dx) .subtract(Duration(days: 1)) .millisecondsSinceEpoch, 5), ); controller?.updateDataSource(addedDataIndex: 0); } } _doubleToDateTime(double dx) { return DateTime.fromMillisecondsSinceEpoch(dx.round()); } } ```

Screenshots or Video

In the code sample, the error does not become visible in the UI, but it can definitely affect other examples as the callback is ended due to a thrown error.

Stack Traces

Stack Traces ```dart ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════ The following IndexError was thrown during a scheduler callback: RangeError (index): Index out of range: no indices are valid: 0 When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw_ dart-sdk/lib/_internal/js_dev_runtime/private/js_array.dart 600:7 _get] packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 6129:33 [_computeStackedValues] packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 6068:7 [_calculateStackingValues] packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 6398:5 updateDataPoints packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 2693:15 updateDataSource reproduce.dart 84:19 updateData reproduce.dart 61:13 packages/flutter/src/widgets/framework.dart 1203:30 setState reproduce.dart 60:11 packages/flutter/src/scheduler/binding.dart 1386:7 [_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1322:11 handleDrawFrame packages/flutter/src/scheduler/binding.dart 1169:5 [_handleDrawFrame] lib/_engine/engine/platform_dispatcher.dart 1346:5 invoke lib/_engine/engine/platform_dispatcher.dart 260:5 invokeOnDrawFrame lib/_engine/engine/initialization.dart 185:36 dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 550:37 _checkAndCall dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 555:39 dcall ════════════════════════════════════════════════════════════════════════════════════════════════════ ```

On which target platforms have you observed this bug?

Web

Flutter Doctor output

Doctor output ```console [√] Flutter (Channel stable, 3.19.5, on Microsoft Windows [Version 10.0.19045.4291], locale de-DE) • Flutter version 3.19.5 on channel stable at C:\Users\Niels\Documents\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 300451adae (3 weeks ago), 2024-03-27 21:54:07 -0500 • Engine revision e76c956498 • Dart version 3.3.3 • DevTools version 2.31.1 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 34.0.0-rc4) • Android SDK at C:\Users\Niels\AppData\Local\Android\Sdk • Platform android-34, build-tools 34.0.0-rc4 • Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Users\Niels\AppData\Local\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Community 2022 17.8.6) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community • Visual Studio Community 2022 version 17.8.34525.116 • Windows 10 SDK version 10.0.19041.0 [√] Android Studio (version 2021.2) • Android Studio at C:\Program Files\Android\Android Studio • Flutter plugin can be installed from: https://plugins.jetbrains.com/plugin/9212-flutter • Dart plugin can be installed from: https://plugins.jetbrains.com/plugin/6351-dart • Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840) [√] VS Code, 64-bit edition (version 1.87.2) • VS Code at C:\Program Files\Microsoft VS Code • Flutter extension version 3.86.0 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19045.4291] • Chrome (web) • chrome • web-javascript • Google Chrome 123.0.6312.123 • Edge (web) • edge • web-javascript • Microsoft Edge 123.0.2420.97 [√] Network resources • All expected network resources are available. • No issues found! ```
PreethikaSelvam commented 3 weeks ago

Hi @DrNiels,

We can replicate the reported issue. This issue is scheduled to be fixed in our upcoming weekly release which is scheduled on April 30, 2024. We will update you here once the release is rolled out and we appreciate your patience until then.

Regards,

Preethika Selvam.

PreethikaSelvam commented 2 weeks ago

Hi @DrNiels,

We would like to let you know that the reported issue is fixed and rolled out in our patch release. We kindly request you to upgrade the syncfusion_flutter_charts package to the latest version below.

Version: https://pub.dev/packages/syncfusion_flutter_charts/versions/25.1.42+1

Root cause: Y values lists are cleared instead of stacked values lists while dynamically update data points.

If you have any further queries, please feel free to reach out to us.

Regards,

Preethika Selvam.

DrNiels commented 5 days ago

Seems to work as intended, thank you for the fix!