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

Dispose method needs to cancel timer #3

Closed
alfredjingle opened this issue Aug 14, 2020 · 5 comments · Fixed by #4
Closed

Dispose method needs to cancel timer #3

alfredjingle opened this issue Aug 14, 2020 · 5 comments · Fixed by #4
Labels
bug Something isn't working

Comments

@alfredjingle
Copy link

Hi,

Thanks for the great plugin!

Just noticed one small issue in the dispose method. If the timer is started and the widget is then disposed before the timer is stopped, Timer.periodic() will still try to add events to the now closed PublishSubjects. See the error below:

I/flutter (21245): I/flutter (21245): #0 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:249:24) I/flutter (21245): #1 Subject._add package:rxdart/…/subjects/subject.dart:141 I/flutter (21245): #2 Subject.add package:rxdart/…/subjects/subject.dart:135 I/flutter (21245): #3 StopWatchTimer._handle package:stop_watch_timer/stop_watch_timer.dart:185 I/flutter (21245): #4 _rootRunUnary (dart:async/zone.dart:1198:47) I/flutter (21245): #5 _CustomZone.runUnary (dart:async/zone.dart:1100:19) I/flutter (21245): #6 _CustomZone.runUnaryGuarded (dart:async/zone.dart:1005:7) I/flutter (21245): #7 _CustomZone.bindUnaryCallbackGuarded.<anonymous closure> (dart:async/zone.dart:1042:26) I/flutter (21245): #8 _rootRunUnary (dart:async/zone.dart:1206:13) I/flutter (21245): #9 _CustomZone.runUnary (dart:async/zone.dart:1100:19) I/flutter (21245): #10 _CustomZone.bindUnaryCallback.<anonymous closure> (dart:async/zone.dart:1026:26) I/flutter (21245): #11 _Closure.call (dart:core-patch/function.dart) I/flutter (21245): #12 _Timer._runTimers (dart:isolate-patch/timer_impl.dart:397:19) I/flutter (21245): #13 _Timer._handleMessage (dart:isolate-patch/timer_impl.dart:428:5) I/flutter (21245): #14 _Closure.call (dart:c I/flutter (21245): Error caught by Crashlytics plugin <recordError>: I/flutter (21245): Bad state: Cannot add new events after calling close

I fixed it locally by calling _timer.close(); in the first line of the dispose() method.

@hukusuke1007
Copy link
Owner

Thank you for comment.
Sure, I will fix it.

@hukusuke1007 hukusuke1007 added the bug Something isn't working label Aug 14, 2020
@hukusuke1007
Copy link
Owner

I finished it. Please check latest version.

@hukusuke1007 hukusuke1007 linked a pull request Aug 14, 2020 that will close this issue
@alfredjingle
Copy link
Author

Looks good!

Thanks again for making this package :)

@hukusuke1007
Copy link
Owner

close

@heshesh2010
Copy link

heshesh2010 commented May 17, 2023

still buggy in latest release 2.0.0
@hukusuke1007

VERBOSE-2:dart_vm_initializer.cc(41)] Unhandled Exception: Bad state: Cannot add new events after calling close
#0 _BroadcastStreamController.add (dart:async/broadcast_stream_controller.dart:243:24)
#1 Subject._add
subject.dart:151
#2 Subject.add
subject.dart:141
#3 new StopWatchTimer.
stop_watch_timer.dart:57
#4 _RootZone.runUnaryGuarded (dart:async/zone.dart:1594:10)
#5 _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:339:11)
#6 _DelayedData.perform (dart:async/stream_impl.dart:515:14)
#7 _PendingEvents.handleNext (dart:async/stream_impl.dart:620:11)
#8 _PendingEvents.schedule. (dart:async/stream_impl.dart:591:7)
#9 _microtaskLoop (dart:async/schedule_microtask.dart:40:21)
#10 _startMicrotaskLoop (dart:async/schedule_microtask.dart:49:5)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants