Stopwatch class
A stopwatch which measures time while it's running.
A stopwatch is either running or stopped.It measures the elapsed time that passes while the stopwatch is running.
When a stopwatch is initially created, it is stopped and has measured noelapsed time.
The elapsed time can be accessed in various formats usingelapsed,elapsedMilliseconds,elapsedMicroseconds orelapsedTicks.
The stopwatch is started by callingstart.
Example:
final stopwatch = Stopwatch();print(stopwatch.elapsedMilliseconds); // 0print(stopwatch.isRunning); // falsestopwatch.start();print(stopwatch.isRunning); // trueTo stop or pause the stopwatch, usestop.Usestart to continue again when only pausing temporarily.
stopwatch.stop();print(stopwatch.isRunning); // falseDuration elapsed = stopwatch.elapsed;await Future.delayed(const Duration(seconds: 1));assert(stopwatch.elapsed == elapsed); // No measured time elapsed.stopwatch.start(); // Continue measuring.Thereset method sets the elapsed time back to zero.It can be called whether the stopwatch is running or not,and doesn't change whether it's running.
// Do some work.stopwatch.stop();print(stopwatch.elapsedMilliseconds); // Likely > 0.stopwatch.reset();print(stopwatch.elapsedMilliseconds); // 0Constructors
Properties
- elapsed→Duration
- TheelapsedTicks counter converted to aDuration.no setter
- elapsedMicroseconds→int
- TheelapsedTicks counter converted to microseconds.no setter
- elapsedMilliseconds→int
- TheelapsedTicks counter converted to milliseconds.no setter
- elapsedTicks→int
- The elapsed number of clock ticks since callingstart while theStopwatch is running.no setter
- frequency→int
- Frequency of the elapsed counter in Hz.no setter
- hashCode→int
- The hash code for this object.no setterinherited
- isRunning→bool
- Whether theStopwatch is currently running.no setter
- runtimeType→Type
- A representation of the runtime type of the object.no setterinherited
Methods
- noSuchMethod(
Invocationinvocation)→ dynamic - Invoked when a nonexistent method or property is accessed.inherited
- reset(
)→ void - Resets theelapsed count to zero.
- start(
)→ void - Starts theStopwatch.
- stop(
)→ void - Stops theStopwatch.
- toString(
)→String - A string representation of this object.inherited
Operators
- operator ==(
Objectother)→bool - The equality operator.inherited