hukusuke1007 / stop_watch_timer

This is Stop Watch Timer for flutter plugin.🏃‍♂️

Home Page:https://pub.dev/packages/stop_watch_timer

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Dispose method needs to cancel timer

alfredjingle opened this issue · comments

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.

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

I finished it. Please check latest version.

Looks good!

Thanks again for making this package :)

close

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)