elapsed_timer 0.1.0 copy "elapsed_timer: ^0.1.0" to clipboard
elapsed_timer: ^0.1.0 copied to clipboard

A package contains ElapsedTimer, which allows easy access to the elapsed time of your timer.

Features #

This package targets the simplicity of accessing the elapsed time from the timer. A necessary Stopwatch for the 'elapsed' property is included in the ElapsedTimer, allowing you to:

final timer = ElapsedTimer(const Duration(seconds: 5), () => print('All done'));
// Somewhere in the code:
final elapsed = timer.elapsed;

instead of maintaining synchronization between the Timer and the corresponding Stopwatch:

final timer1 = Timer(const Duration(seconds: 5), () => print('All done'));
final stopwatchForTimer1 = StopWatch()..start();

// Somewhere in the code:
final elapsed = stopwatchForTimer1.elapsed;

// Somewhere in the code:
timer1.cancel();
stopwatchForTimer1.stop();

The 'elapsed' property for Timer is especially helpful when handling multiple asynchronous calls starting the same timer, as it helps to avoid throttling:

ElapsedTimer? updateTimer;

void updateData() {
  if (updateTimer != null && updateTimer!.isActive) {
    final runningFor = updateTimer!.elapsed;
    if (runningFor < Duration(seconds: 1)) {
      print('updateData is called already');
      return;
    }
  }
  updateTimer?.cancel();
  updateTimer = ElapsedTimer(const Duration(seconds: 10), updateData);
  // Proceed with some updates
}

Usage #

final timer = ElapsedTimer(const Duration(seconds: 5), () => print('All done'));
// Somewhere in the code:
final elapsed = timer.elapsed;

Issues #

Can be found here.

6
likes
150
pub points
40%
popularity

Publisher

verified publisherkabadh.com

A package contains ElapsedTimer, which allows easy access to the elapsed time of your timer.

Repository (GitHub)
View/report issues

Topics

#timer #elapsed-time

Documentation

API reference

License

BSD-3-Clause (license)

More

Packages that depend on elapsed_timer