lap method

int lap({
  1. String? ref,
})

Returns elapsed seconds for ref without resetting. Call commitLap after the value has been safely captured/stored.

Typical usage:

final duration = stopwatch.lap(ref: 'page_book1');
pagesDuration[page] = (pagesDuration[page] ?? 0) + duration;
stopwatch.commitLap(ref: 'page_book1'); // safe to reset now

Implementation

int lap({String? ref}) {
  ref ??= currentReference;
  if (_stopwatches.containsKey(ref)) {
    if (_stopwatches[ref]!.isRunning) {
      return _accumulatedTime[ref]! + _stopwatches[ref]!.elapsed.inSeconds;
    }
    return _accumulatedTime[ref]!;
  }
  return 0;
}