From 543293d2c446a27b6f8d1c7483be4c2324d4b8ea Mon Sep 17 00:00:00 2001 From: Shohei Nakagawa Date: Tue, 29 Jun 2021 00:50:08 +0900 Subject: [PATCH] Modified initialPresetTime. --- CHANGELOG.md | 5 ++++- README.md | 46 ++++++++++++++++++--------------------- lib/stop_watch_timer.dart | 14 +++++++----- pubspec.yaml | 6 ++--- 4 files changed, 36 insertions(+), 35 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ab722df..ce034b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,7 @@ -# 1.3.0 +# 1.3.1 +Modified initialPresetTime. + +## 1.3.0 Can be set preset time in running timer. Added clearPresetTime and onEnded. ## 1.2.0+1 diff --git a/README.md b/README.md index d8f39b4..ef3b2db 100644 --- a/README.md +++ b/README.md @@ -1,11 +1,9 @@ # stop_watch_timer -This is Stop Watch Timer. +Simple CountUp timer / CountDown timer. It easily create app of stopwatch. [https://pub.dev/packages/stop_watch_timer](https://pub.dev/packages/stop_watch_timer) -Countup Timer & Countdown Timer - ![countup_timer_demo](./countup_timer_demo.gif) ![countdown_timer_demo](./countdown_timer_demo.gif) ## Example code @@ -124,6 +122,26 @@ _stopWatchTimer.onExecute.add(StopWatchExecute.reset); _stopWatchTimer.onExecute.add(StopWatchExecute.lap); ``` +Can be set preset time. This case is "00:01.23". + +```dart +// Set Millisecond. +_stopWatchTimer.setPresetTime(mSec: 1234); +``` + +When timer is idle state, can be set this. + +```dart +// Set Hours. (ex. 1 hours) +_stopWatchTimer.setPresetHoursTime(1); + +// Set Minute. (ex. 30 minute) +_stopWatchTimer.setPresetMinuteTime(30); + +// Set Second. (ex. 120 second) +_stopWatchTimer.setPresetSecondTime(120); +``` + ### Using callback ```dart @@ -345,25 +363,3 @@ Can be used [getDisplayTime](https://github.com/hukusuke1007/stop_watch_timer/bl For example, 1 hours and 30 minute and 50 second and 20 millisecond => "01:30:50.20" And can be set enable/disable display time and change split character. - -### Set Preset Time - -Can be set preset time. This case is "00:01.23". - -```dart -// Set Millisecond. -_stopWatchTimer.setPresetTime(mSec: 1234); -``` - -When timer is idle state, can be set this. - -```dart -// Set Hours. (ex. 1 hours) -_stopWatchTimer.setPresetHoursTime(1); - -// Set Minute. (ex. 30 minute) -_stopWatchTimer.setPresetMinuteTime(30); - -// Set Second. (ex. 120 second) -_stopWatchTimer.setPresetSecondTime(120); -``` \ No newline at end of file diff --git a/lib/stop_watch_timer.dart b/lib/stop_watch_timer.dart index 8265eb1..91d12c4 100644 --- a/lib/stop_watch_timer.dart +++ b/lib/stop_watch_timer.dart @@ -39,7 +39,7 @@ class StopWatchTimer { }) { /// Set presetTime _presetTime = presetMillisecond; - initialPresetTime = presetMillisecond; + _initialPresetTime = presetMillisecond; _elapsedTime.listen((value) { _rawTimeController.add(value); @@ -115,6 +115,10 @@ class StopWatchTimer { Stream get execute => _executeController; Sink get onExecute => _executeController.sink; + bool get isRunning => _timer != null && _timer!.isActive; + int get initialPresetTime => _initialPresetTime; + + /// Private Timer? _timer; int _startTime = 0; int _stopTime = 0; @@ -122,9 +126,7 @@ class StopWatchTimer { int? _second; int? _minute; List _records = []; - - bool get isRunning => _timer != null && _timer!.isActive; - late int initialPresetTime; + late int _initialPresetTime; /// Get display time. static String getDisplayTime( @@ -244,10 +246,10 @@ class StopWatchTimer { void clearPresetTime() { if (mode == StopWatchMode.countUp) { - _presetTime = initialPresetTime; + _presetTime = _initialPresetTime; _elapsedTime.add(isRunning ? _getCountUpTime(_presetTime) : _presetTime); } else if (mode == StopWatchMode.countDown) { - _presetTime = initialPresetTime; + _presetTime = _initialPresetTime; _elapsedTime .add(isRunning ? _getCountDownTime(_presetTime) : _presetTime); } else { diff --git a/pubspec.yaml b/pubspec.yaml index 930a9bf..da07f14 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,11 +1,11 @@ name: stop_watch_timer -description: This is Stop Watch Timer for flutter plugin. It easily create application of stop watch for sports if use this plugin. -version: 1.3.0 +description: Simple CountUp timer / CountDown timer. It easily create app of stopwatch. +version: 1.3.1 repository: https://github.com/hukusuke1007/stop_watch_timer homepage: https://github.com/hukusuke1007/stop_watch_timer environment: - sdk: '>=2.12.0-0 <3.0.0' + sdk: '>=2.12.0 <3.0.0' dependencies: flutter: