google / charts

https://pub.dev/packages/charts_flutter
Apache License 2.0
2.81k stars 1.22k forks source link

setState() called after dispose(): BaseChartState #277

Open speedlightwp opened 5 years ago

speedlightwp commented 5 years ago

I am using BottomNavigation with PageView and Charts Flutter (charts_flutter: ^0.6.0). I realise if I use pageController.jumpToPage(index), it will cause the error setState() called after dispose(): BaseChartState. If I change to pageController.animateToPage, occasionally it will produce the error.

flutter: ══╡ EXCEPTION CAUGHT BY SCHEDULER LIBRARY ╞═════════════════════════════════════════════════════════ flutter: The following assertion was thrown during a scheduler callback: flutter: setState() called after dispose(): BaseChartState#64182(lifecycle state: defunct, not flutter: mounted, tickers: tracking 0 tickers) flutter: This error happens if you call setState() on a State object for a widget that no longer appears in flutter: the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error flutter: can occur when code calls setState() from a timer or an animation callback. The preferred solution flutter: is to cancel the timer or stop listening to the animation in the dispose() callback. Another flutter: solution is to check the "mounted" property of this object before calling setState() to ensure the flutter: object is still in the tree. flutter: This error might indicate a memory leak if setState() is being called because another object is flutter: retaining a reference to this State object after it has been removed from the tree. To avoid memory flutter: leaks, consider breaking the reference to this object during dispose().

I need to edit base_chart_state.dart file (line 72):

@override void requestRebuild() { if(mounted) setState(() {}); }

After adding if(mounted), it solves the problem.

yayxs commented 4 years ago

中文:请问解决了吗?我的问题是: setState() called after dispose(): BaseChartState#07b36(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)


English: Has it been resolved?

setState() called after dispose(): BaseChartState#07b36(lifecycle state: defunct, not mounted, tickers: tracking 0 tickers)

SairamNaragoni commented 4 years ago

I am facing with the same issue . I am using charts in a tab view.

chitgoks commented 4 years ago

I am facing with the same issue . I am using charts in a tab view.

confirmed. also getting this error when used inside a tab

LAPPIT commented 3 years ago

I have the same issue, using a TimeSeriesChart with stacked bars, in a SliverList.

Stacktrace:

I/flutter (10650): When the exception was thrown, this was the stack: I/flutter (10650): #0 State.setState. (package:flutter/src/widgets/framework.dart:1204:9) I/flutter (10650): #1 State.setState (package:flutter/src/widgets/framework.dart:1239:6) I/flutter (10650): #2 BaseChartState.requestRebuild (package:charts_flutter/src/base_chart_state.dart:71:5) I/flutter (10650): #3 ChartContainerRenderObject.requestRebuild.doRebuild (package:charts_flutter/src/chart_container.dart:268:19) I/flutter (10650): #4 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1117:15) I/flutter (10650): #5 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1064:9) I/flutter (10650): #6 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:972:5) I/flutter (10650): #10 _invoke (dart:ui/hooks.dart:253:10) I/flutter (10650): #11 _drawFrame (dart:ui/hooks.dart:211:3) I/flutter (10650): (elided 3 frames from dart:async) I