Skip to content
This repository has been archived by the owner on Dec 19, 2024. It is now read-only.

Commit

Permalink
🐛 Fixed bug that caused the stopwatch to go in idle when the device i…
Browse files Browse the repository at this point in the history
…s locked
  • Loading branch information
GiorgioBertolotti committed Dec 8, 2019
1 parent 4b04daa commit ca6dfa1
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 7 deletions.
21 changes: 15 additions & 6 deletions pro_time/lib/model/time.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,29 @@ class TimerInfo {
}

class ProTimeStopwatch {
final Stopwatch _stopWatch = Stopwatch();
Duration _initialOffset;
DateTime _start;

ProTimeStopwatch({Duration initialOffset = Duration.zero})
: _initialOffset = initialOffset;

start() => _stopWatch.start();
start() {
_start = DateTime.now();
}

stop() => _stopWatch.stop();
stop() {
if (_start != null) {
_initialOffset += DateTime.now().difference(_start);
_start = null;
}
}

reset({Duration newInitialOffset}) {
_stopWatch.reset();
_initialOffset = newInitialOffset ?? _initialOffset;
_start = null;
_initialOffset = newInitialOffset ?? Duration.zero;
}

Duration get elapsed => _stopWatch.elapsed + _initialOffset;
Duration get elapsed =>
(_start != null ? DateTime.now().difference(_start) : Duration.zero) +
_initialOffset;
}
2 changes: 1 addition & 1 deletion pro_time/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: pro_time
description: Projects time tracking app.

version: 1.3+7
version: 1.3.1+8

environment:
sdk: ">=2.2.0 <3.0.0"
Expand Down

0 comments on commit ca6dfa1

Please sign in to comment.