A count-down timer that can be configured to fire once or repeatedly.
The timer counts down from the specified duration to 0. When the timer reaches 0, the timer invokes the specified callback function. Use a periodic timer to repeatedly count down the same interval.
A negative duration is treated the same as a duration of 0. If the duration is statically known to be 0, consider using run.
Frequently the duration is either a constant or computed as in the following example (taking advantage of the multiplication operator of the Duration class):
const TIMEOUT = const Duration(seconds: 3);
const ms = const Duration(milliseconds: 1);
startTimeout([int milliseconds]) {
var duration = milliseconds == null ? TIMEOUT : ms * milliseconds;
return new Timer(duration, handleTimeout);
}
...
void handleTimeout() { // callback function
...
}
Note: If Dart code using Timer is compiled to JavaScript, the finest granularity available in the browser is 4 milliseconds.
See Stopwatch for measuring elapsed time.
Static Methods
Constructors
Properties
Operators
-
operator ==(
other) → bool -
The equality operator.…
inherited
Methods
-
cancel(
) → void -
Cancels the timer.
-
noSuchMethod(
Invocation invocation) → dynamic -
noSuchMethod is invoked when users invoke a non-existent method on an object. The name of the method and the arguments of the invocation are passed to noSuchMethod in an Invocation. If noSuchMethod returns a value, that value becomes the result of the original invocation.…
inherited -
toString(
) → String -
Returns a string representation of this object.
inherited