Skip to content

Commit

Permalink
Modified initialPresetTime.
Browse files Browse the repository at this point in the history
  • Loading branch information
hukusuke1007 committed Jun 28, 2021
1 parent ec09ab0 commit 543293d
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 35 deletions.
5 changes: 4 additions & 1 deletion 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
Expand Down
46 changes: 21 additions & 25 deletions 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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
```
14 changes: 8 additions & 6 deletions lib/stop_watch_timer.dart
Expand Up @@ -39,7 +39,7 @@ class StopWatchTimer {
}) {
/// Set presetTime
_presetTime = presetMillisecond;
initialPresetTime = presetMillisecond;
_initialPresetTime = presetMillisecond;

_elapsedTime.listen((value) {
_rawTimeController.add(value);
Expand Down Expand Up @@ -115,16 +115,18 @@ class StopWatchTimer {
Stream<StopWatchExecute> get execute => _executeController;
Sink<StopWatchExecute> get onExecute => _executeController.sink;

bool get isRunning => _timer != null && _timer!.isActive;
int get initialPresetTime => _initialPresetTime;

/// Private
Timer? _timer;
int _startTime = 0;
int _stopTime = 0;
late int _presetTime;
int? _second;
int? _minute;
List<StopWatchRecord> _records = [];

bool get isRunning => _timer != null && _timer!.isActive;
late int initialPresetTime;
late int _initialPresetTime;

/// Get display time.
static String getDisplayTime(
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions 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:
Expand Down

0 comments on commit 543293d

Please sign in to comment.