diff --git a/pro_time/lib/model/time.dart b/pro_time/lib/model/time.dart index a6fdb82..4b4cde0 100644 --- a/pro_time/lib/model/time.dart +++ b/pro_time/lib/model/time.dart @@ -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; } diff --git a/pro_time/pubspec.yaml b/pro_time/pubspec.yaml index 61577af..b480f19 100644 --- a/pro_time/pubspec.yaml +++ b/pro_time/pubspec.yaml @@ -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"