Skip to content

Instantly share code, notes, and snippets.

@aria-dev
Last active June 19, 2020 15:58
Show Gist options
  • Save aria-dev/04b6eac9e1c173a62398bce03b4fe649 to your computer and use it in GitHub Desktop.
Save aria-dev/04b6eac9e1c173a62398bce03b4fe649 to your computer and use it in GitHub Desktop.
Extended Stopwatch class
//////////Usage of the StopWatch class //////////////////////
void main() {
var stopwatch = new StopWatch();
stopwatch.start();
stopwatch.milliseconds = 10000; //10 seconds have passed
print(stopwatch.elapsedDuration);
stopwatch.stop();
}
//////////////////////////////////////////////////////////////////////
// StopWatch class //
/////////////////////////////////////////////////////////////////////
class StopWatch extends Stopwatch{
int _starterMilliseconds = 0;
StopWatch();
get elapsedDuration{
return Duration(
microseconds:
this.elapsedMicroseconds + (this._starterMilliseconds * 1000)
);
}
get elapsedMillis{
return this.elapsedMilliseconds + this._starterMilliseconds;
}
set milliseconds(int timeInMilliseconds){
this._starterMilliseconds = timeInMilliseconds;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment