duration property
set
duration
(Duration duration)
Changes the timer duration.
If the new duration is greater than the current one, then a new duration
value is set.
If the new duration is less than the current duration, then a check is
made to see if the new duration value points to a time in the past.
If the time has already expired, the duration is set to the current time
and the timer is terminated by calling the handler.
Does not perform any action if the timer is no longer active.
Implementation
set duration(Duration duration) {
if (_callback == null) {
return;
}
if (duration.inMicroseconds == _duration.inMicroseconds) {
return;
}
final elapsedMicroseconds = _stopwatch.elapsedMicroseconds;
final remaining = duration.inMicroseconds - elapsedMicroseconds;
if (remaining <= 0) {
_duration = Duration(microseconds: elapsedMicroseconds);
_handle();
return;
}
_duration = duration;
_timer.cancel();
duration = Duration(microseconds: remaining);
_timer = Timer(duration, _handle);
}