Skip to content
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

legendItemBuilder throwing exception #228

Closed
leidig54 opened this issue Oct 18, 2020 · 3 comments
Closed

legendItemBuilder throwing exception #228

leidig54 opened this issue Oct 18, 2020 · 3 comments

Comments

@leidig54
Copy link

leidig54 commented Oct 18, 2020

Hi chaps,

Am getting the below error when trying to use the legend ItemBuilder.

The following assertion was thrown building LayoutBuilder:
setState() called after dispose(): _DataLabelRendererState#7f349(lifecycle state: defunct, not mounted, ticker inactive)

This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.

The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().

The relevant error-causing widget was
SfCartesianChart
lib/…/presentation/profile_home_ui.dart:203
When the exception was thrown, this was the stack
#0      State.setState.<anonymous closure>
package:flutter/…/widgets/framework.dart:1233
#1      State.setState
package:flutter/…/widgets/framework.dart:1268
#2      _DataLabelRendererState.render
package:syncfusion_flutter_charts/…/common/renderer.dart:74
#3      _setAnimationStatus
package:syncfusion_flutter_charts/…/utils/helper.dart:3198
#4      _ContainerArea._bindSeriesWidgets
package:syncfusion_flutter_charts/…/base/chart_base.dart:2233
...
Legend(
                                              isVisible: true,
                                              position: LegendPosition.bottom,
                                              legendItemBuilder: (legendText,
                                                  series, point, seriesIndex) {
                                                return Padding(
                                                  padding: const EdgeInsets
                                                          .symmetric(
                                                      horizontal: 8.0,
                                                      vertical: 4),
                                                  child: Column(
                                                    mainAxisSize:
                                                        MainAxisSize.min,
                                                    children: [
                                                      Text(legendText),
                                                      Icon(Icons.thumb_down),
                                                    ],
                                                  ),
                                                );
                                              }),

Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel beta, 1.23.0-18.1.pre, on Mac OS X 10.15.6 19G2021 x86_64, locale en-GB)

[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.3)
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 3.6)
[✓] VS Code (version 1.50.1)
[✓] Connected device (4 available)

• No issues found!

@SriramKiranSenthilkumar
Copy link
Contributor

SriramKiranSenthilkumar commented Oct 19, 2020

Hi @leidig54,

Thanks for contacting Syncfusion Support. We have analyzed your scenario with the provided information and we tried to replicate it at our end with the help of the provided code snippet. unfortunately, the chart rendered properly along with the legendItemBuilder and no reported exceptions were thrown. However, on further analyzing the error statements we assume that you must have added the legendItemBuilder in your code while the application for running and you would have hot reloaded and due to which this error could have been thrown because in the error statements it is said that "this error happens if you call setState() on a State object for a widget that no longer appears in the widget tree" which means that as the builder returns a widget and hot-reloading or calling setState in the application will throw this exception as the widget is not yet included in the widget tree of the application. So, this exception can be overcome by either rebuilding or hot-restarting the Flutter application.

Please check with the above response and try rebuilding the application and let us know if the reported problem still occurs.

Regards,
Sriram Kiran

@leidig54
Copy link
Author

Hi Sriram,

The error occurs whenever the state is changed - for example updating the chart at any point. I am using Provider to update the state. Hot restarting or even fully restarting the app does not solve the issue.

@SriramKiranSenthilkumar
Copy link
Contributor

Hi @leidig54,

Thanks for the revert. We have analysed your query with the provided information and we tried to replicate the reported issue by using provider available in Flutter framework to update the state regarding the legendItemBuilder throwing exception when the state is changed. Unfortunately, we are not able to replicate the reported issue at our end.

Since we are not aware on the exact scenario on which the issue is replicating, we kindly request you to try replicating the reported issue in the below-attached sample so that it will be helpful in further analysis and to provide the solution sooner.

Sample: sample.zip

Regards,
Sriram Kiran

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

No branches or pull requests

2 participants