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

markNeedsBuild() called during build with MaterialPageRoute #1820

Open DrNiels opened 4 weeks ago

DrNiels commented 4 weeks ago

Bug description

In my application, I get the following error when routing via MaterialPageRoute. In the provided example, it only seems to be cosmetic while my complete app completely fails. However, I hope that the issue remains the same. The structure with Hero and Card seems to be relevant as well as an empty data source.

In the example, the structure obviously seems unnecessary, but is required for proper maximizing in the complete app.

I use syncfusion_flutter_charts 25.1.40

Steps to reproduce

Route page by clicking the "ABC" icon button

Code sample

Code sample ```dart import 'package:flutter/material.dart'; import 'package:syncfusion_flutter_charts/charts.dart'; void main() async { runApp( MaterialApp( home: HeroCard(), ), ); } class HeroCard extends StatelessWidget { final GlobalKey styledCardKey = new GlobalKey(); @override Widget build(BuildContext context) { return Hero( tag: 'heroCard', child: Card( key: styledCardKey, // No error without key child: Row( children: [ SfCartesianChart( series: [ SplineSeries( xValueMapper: (num value, int index) => index, yValueMapper: (num value, int index) => index, dataSource: [], // No error, if some data is available, e.g., [1] ) ], ), IconButton( onPressed: () { Navigator.push( context, MaterialPageRoute( maintainState: false, fullscreenDialog: true, builder: (BuildContext context) { return HeroCard(); }, ), ); }, icon: Icon(Icons.abc), ), ], ), ), ); } } ```

Screenshots or Video

Not applicable, as the error is thrown but does not seem to cause any complications in the example. However, in my complete app, it definitely causes serious complications.

Stack Traces

Stack Traces ```dart ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════ The following assertion was thrown while rebuilding dirty elements: setState() or markNeedsBuild() called during build. This CartesianChartArea widget cannot be marked as needing to build because the framework is already in the process of building widgets. A widget can be marked as needing to be built during the build phase only if one of its ancestors is currently building. This exception is allowed because the framework builds parent widgets before children, which means a dirty descendant will always be built. Otherwise, the framework might not visit this widget during this build phase. The widget on which setState() or markNeedsBuild() was called was: CartesianChartArea The widget which was currently being built when the offending call was made was: SplineSeries When the exception was thrown, this was the stack: dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 297:3 throw_ packages/flutter/src/widgets/framework.dart 5042:9 packages/flutter/src/widgets/framework.dart 5053:14 markNeedsBuild packages/syncfusion_flutter_charts/src/charts/base.dart 126:7 [_scheduleUpdate] packages/syncfusion_flutter_charts/src/charts/base.dart 269:5 scheduleUpdateFrame packages/syncfusion_flutter_charts/src/charts/base.dart 137:24 markNeedsUpdate packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 3276:7 set dataSource packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 696:9 packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 719:18 updateRenderObject packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 3231:11 updateRenderObject packages/syncfusion_flutter_charts/src/charts/series/chart_series.dart 5582:11 updateRenderObject packages/syncfusion_flutter_charts/src/charts/series/spline_series.dart 449:11 updateRenderObject packages/flutter/src/widgets/framework.dart 6491:6 [_performRebuild] packages/flutter/src/widgets/framework.dart 6482:5 performRebuild packages/flutter/src/widgets/framework.dart 5196:7 rebuild packages/flutter/src/widgets/framework.dart 2904:18 buildScope packages/flutter/src/widgets/binding.dart 989:9 drawFrame packages/flutter/src/rendering/binding.dart 448:5 [_handlePersistentFrameCallback] packages/flutter/src/scheduler/binding.dart 1386:7 [_invokeFrameCallback] packages/flutter/src/scheduler/binding.dart 1311:9 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 The element being rebuilt at the time was index 30 of 48: SplineSeries ════════════════════════════════════════════════════════════════════════════════════════════════════ ```

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! ```
LokeshPalani commented 3 weeks ago

Hi @DrNiels,

We have reproduced the issue you reported on our end and the issue is scheduled to be fixed in our upcoming weekly patch release on May 07, 2024. We will notify you here once the release has been rolled out, and we appreciate your patience in the meantime.

Regards, Lokesh P.

LokeshPalani commented 1 week ago

Hi,

The reported issue occurs particularly in the Hero widget when we attempt to navigate to the same page again with an empty chart data source. Due to its complexity, we are unable to resolve this issue within the planned timeline. We are currently working on it and will include the fix in our weekly patch, which is expected to roll out on May 21, 2024.

Regards, Lokesh P.

LavanyaGowtham2021 commented 5 days ago

Hi @DrNiels ,

Currently we are working on this issue, but we need some confirmation your end. Can you please share the reason for reloading the same HeroCard widget again with same page?

Regards, Lavanya A.

DrNiels commented 5 days ago

Obviously, the example here is extremely simplified as I tried to create a minimal example that is easier to handle. In my real application, I provide multiple cards with different content that may include a syncfusion chart. Each card can be maximized, which we solve via routes. Feel free to check out the demo for our app (at this time still without Syncfusion Charts) and how the cards are maximized: https://demo.symcon.de/