@@ -7,10 +7,10 @@ import 'dart:async';
77/// A non-periodic timer that can be restarted any number of times.
88///
99/// Once restarted (via [reset] ), the timer counts down from its original
10- /// duration again .
10+ /// or a passed duration .
1111class RestartableTimer implements Timer {
12- /// The duration of the timer.
13- final Duration _duration ;
12+ /// The default duration of the timer.
13+ final Duration _defaultDuration ;
1414
1515 /// The callback to call when the timer fires.
1616 final ZoneCallback _callback;
@@ -23,21 +23,24 @@ class RestartableTimer implements Timer {
2323
2424 /// Creates a new timer.
2525 ///
26- /// The [_callback] function is invoked after the given [_duration] . Unlike a
27- /// normal non-periodic [Timer] , [_callback] may be called more than once.
28- RestartableTimer (this ._duration, this ._callback)
29- : _timer = Timer (_duration, _callback);
26+ /// The [_callback] function is invoked after the given [_defaultDuration] by
27+ /// default. Unlike a normal non-periodic [Timer] , [_callback] may be called
28+ /// more than once.
29+ RestartableTimer (this ._defaultDuration, this ._callback)
30+ : _timer = Timer (_defaultDuration, _callback);
3031
3132 @override
3233 bool get isActive => _timer.isActive;
3334
34- /// Restarts the timer so that it counts down from its original duration
35- /// again.
35+ /// Restarts the timer so that it counts down again.
3636 ///
3737 /// This restarts the timer even if it has already fired or has been canceled.
38- void reset () {
38+ /// If [duration] is passed it is used for this cycle of the timer but
39+ /// does not change the default duration for this timer if future calls to
40+ /// `reset` omit the [duration] argument.
41+ void reset ([Duration ? duration]) {
3942 _timer.cancel ();
40- _timer = Timer (_duration , _callback);
43+ _timer = Timer (duration ?? _defaultDuration , _callback);
4144 }
4245
4346 @override
0 commit comments