Skip to content

legendItemBuilder throwing exception #228

@leidig54

Description

@leidig54

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!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions