Skip to content

Commit

Permalink
Added preset time feature.
Browse files Browse the repository at this point in the history
  • Loading branch information
hukusuke1007 committed Jul 30, 2020
1 parent 3a68e03 commit 520639c
Show file tree
Hide file tree
Showing 8 changed files with 59 additions and 25 deletions.
4 changes: 2 additions & 2 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

34 changes: 19 additions & 15 deletions .idea/workspace.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 4 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# 0.4.0
# 0.5.0
Added preset time feature.

## 0.4.0
Updated rxdart plugin.

## 0.3.0
Expand Down
9 changes: 9 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -277,4 +277,13 @@ StreamBuilder<List<StopWatchRecord>>(
},
),
```

### Set Preset Time

Can be set preset time. This case is "00:01.23".
When timer is idle state, can be set this.

```dart
_stopWatchTimer.setPresetTime(mSec: 1234);
```
3 changes: 3 additions & 0 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ class _MyAppState extends State<MyApp> {
_stopWatchTimer.minuteTime.listen((value) => print('minuteTime $value'));
_stopWatchTimer.secondTime.listen((value) => print('secondTime $value'));
_stopWatchTimer.records.listen((value) => print('records $value'));

/// Can be set preset time. This case is "00:01.23".
// _stopWatchTimer.setPresetTime(mSec: 1234);
}

@override
Expand Down
24 changes: 19 additions & 5 deletions lib/stop_watch_timer.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:rxdart/rxdart.dart';

class StopWatchRecord {
Expand Down Expand Up @@ -58,6 +59,7 @@ class StopWatchTimer {
Timer _timer;
int _startTime = 0;
int _stopTime = 0;
int _presetTime = 0;
int _second;
int _minute;
List<StopWatchRecord> _records = [];
Expand Down Expand Up @@ -112,7 +114,7 @@ class StopWatchTimer {
}

/// When finish running timer, it need to dispose.
Future dispose() async {
Future<void> dispose() async {
await _elapsedTime.close();
await _rawTimeController.close();
await _secondTimeController.close();
Expand All @@ -122,7 +124,16 @@ class StopWatchTimer {
}

/// Get display millisecond time.
bool isRunning() => _timer != null ? _timer.isActive : false;
// ignore: avoid_bool_literals_in_conditional_expressions
bool get isRunning => _timer != null ? _timer.isActive : false;

/// Set preset time. 1000 mSec => 1 sec
void setPresetTime({@required int mSec}) {
if (_timer == null) {
_presetTime = mSec;
_elapsedTime.add(_presetTime);
}
}

Future _configure() async {
_elapsedTime.listen((value) {
Expand Down Expand Up @@ -170,8 +181,11 @@ class StopWatchTimer {

int _getSecond(int value) => (value / 1000).floor();

void _handle(Timer timer) => _elapsedTime
.add(DateTime.now().millisecondsSinceEpoch - _startTime + _stopTime);
void _handle(Timer timer) =>
_elapsedTime.add(DateTime.now().millisecondsSinceEpoch -
_startTime +
_stopTime +
_presetTime);

void _start() {
if (_timer == null || !_timer.isActive) {
Expand Down Expand Up @@ -199,7 +213,7 @@ class StopWatchTimer {
_minute = null;
_records = [];
_recordsController.add(_records);
_elapsedTime.add(0);
_elapsedTime.add(_presetTime);
}

void _lap() {
Expand Down
4 changes: 2 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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: 0.4.0
version: 0.5.0
repository: https://github.com/hukusuke1007/stop_watch_timer
homepage: https://github.com/hukusuke1007/stop_watch_timer

Expand All @@ -15,4 +15,4 @@ dependencies:
dev_dependencies:
flutter_test:
sdk: flutter
pedantic_mono: any
pedantic_mono: 1.9.1
1 change: 1 addition & 0 deletions stop_watch_timer.iml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/stop_watch_timer/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/stop_watch_timer/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/.symlinks/plugins/stop_watch_timer/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
Expand Down

0 comments on commit 520639c

Please sign in to comment.