CountdownTimer constructor
Creates a new CountdownTimer that fires events in increments of
increment
, until the duration
has passed.
stopwatch
is for testing purposes. If you're using CountdownTimer and
need to control time in a test, pass a mock or a fake. See FakeAsync
and FakeStopwatch.
Implementation
CountdownTimer(Duration duration, this.increment, {Stopwatch? stopwatch})
: _duration = duration,
_stopwatch = stopwatch ?? Stopwatch(),
_controller = StreamController<CountdownTimer>.broadcast(sync: true) {
_timer = Timer.periodic(increment, _tick);
_stopwatch.start();
}