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, Duration increment, {Stopwatch stopwatch})
: _duration = duration,
increment = increment,
_stopwatch = stopwatch == null ? new Stopwatch() : stopwatch,
_controller =
new StreamController<CountdownTimer>.broadcast(sync: true) {
_timer = new Timer.periodic(increment, _tick);
_stopwatch.start();
}