Skyost / FlutterWeekView

Displays a highly customizable week view (or day view) which is able to display events, to be scrolled, to be zoomed-in & out and a lot more !
https://pub.dev/packages/flutter_week_view
MIT License
208 stars 89 forks source link

Need to remove FrameCallback when WeekView is disposed #37

Closed hnvn closed 4 years ago

hnvn commented 4 years ago

I encounter this error:


════════ Exception caught by scheduler library ═════════════════════════════════
The following assertion was thrown during a scheduler callback:
setState() called after dispose(): _DayViewState#5c1ac(lifecycle state: defunct, not mounted)

It is caused by codes inside FrameCallback of WidgetsBinding.instance.addPostFrameCallback() are triggered even after WeekView is disposed

Skyost commented 4 years ago

Is this the full stacktrace ?

hnvn commented 4 years ago

Full logs:

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().

When the exception was thrown, this was the stack
#0      State.setState.<anonymous closure> 
package:flutter/…/widgets/framework.dart:1200
#1      State.setState 
package:flutter/…/widgets/framework.dart:1235
#2      _DayViewState.initState.<anonymous closure> 
package:flutter_week_view/src/day_view.dart:64
#3      SchedulerBinding._invokeFrameCallback 
package:flutter/…/scheduler/binding.dart:1113
#4      SchedulerBinding.handleDrawFrame 
package:flutter/…/scheduler/binding.dart:1060
...