Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# CHANGELOG

## [1.0.5] - Nov 5th, 2020

- Fixed issues
- #[10](https://github.com/DizoftTeam/simple_count_down/issues/10) : Add reinitialise method

## [1.0.4] - June 26th, 2020

- Pull Requests
Expand Down
12 changes: 4 additions & 8 deletions example/android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ apply plugin: 'kotlin-android'
apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"

android {
compileSdkVersion 28
compileSdkVersion 30

sourceSets {
main.java.srcDirs += 'src/main/kotlin'
Expand All @@ -38,12 +38,11 @@ android {

defaultConfig {
// TODO: Specify your own unique Application ID (https://developer.android.com/studio/build/application-id.html).
applicationId "com.example.example"
minSdkVersion 16
targetSdkVersion 28
applicationId "com.example.mobile"
minSdkVersion 24 // 16
targetSdkVersion 30
versionCode flutterVersionCode.toInteger()
versionName flutterVersionName
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}

buildTypes {
Expand All @@ -61,7 +60,4 @@ flutter {

dependencies {
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
testImplementation 'junit:junit:4.12'
androidTestImplementation 'androidx.test:runner:1.1.1'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,6 @@
package com.example.example
package com.example.mobile

import androidx.annotation.NonNull;
import io.flutter.embedding.android.FlutterActivity
import io.flutter.embedding.engine.FlutterEngine
import io.flutter.plugins.GeneratedPluginRegistrant

class MainActivity: FlutterActivity() {
override fun configureFlutterEngine(@NonNull flutterEngine: FlutterEngine) {
GeneratedPluginRegistrant.registerWith(flutterEngine);
}
}
4 changes: 2 additions & 2 deletions example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.4.10'
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.5.0'
classpath 'com.android.tools.build:gradle:4.0.0'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
}
}
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.3-all.zip
70 changes: 50 additions & 20 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MyHomePage extends StatefulWidget {
/// Page state
///
class _MyHomePageState extends State<MyHomePage> {
final CountdownController controller = CountdownController();
final CountdownController _controller = CountdownController();

bool _isPause = true;
bool _isRestart = false;
Expand All @@ -63,33 +63,63 @@ class _MyHomePageState extends State<MyHomePage> {
),
),
body: Center(
child: Countdown(
controller: controller,
seconds: 5,
build: (_, double time) => Text(
time.toString(),
style: TextStyle(
fontSize: 100,
),
),
interval: Duration(milliseconds: 100),
onFinished: () {
print('Timer is done!');
child: Column(
children: <Widget>[
Countdown(
controller: _controller,
seconds: 5,
build: (_, double time) => Text(
time.toString(),
style: TextStyle(
fontSize: 100,
),
),
interval: Duration(milliseconds: 100),
onFinished: () {
print('Timer is done!');

setState(() {
_isRestart = true;
});
},
setState(() {
_isRestart = true;
});
},
),
RaisedButton(
child: Text('Set new Value'),
onPressed: () {
print('show Dialog');
Scaffold.of(context).showBottomSheet(
(BuildContext context) {
return Container(
height: 300,
child: Center(
child: Column(
children: <Widget>[
const Text('Enter new timer value'),
ElevatedButton(
child: Text('Apply'),
onPressed: () {
print('New Button');
},
),
],
),
),
);
},
);
},
),
],
),
),
floatingActionButton: FloatingActionButton(
child: Icon(buttonIcon),
onPressed: () {
final isCompleted = controller.isCompleted;
isCompleted ? controller.restart() : controller.pause();
final isCompleted = _controller.isCompleted;
isCompleted ? _controller.restart() : _controller.pause();

if (!isCompleted && !_isPause) {
controller.resume();
_controller.resume();
}

if (isCompleted) {
Expand Down
19 changes: 19 additions & 0 deletions lib/timer_controller.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
// Flutter libs
import 'package:flutter/widgets.dart';

typedef IntCallback = Function(int value);

///
/// Controller for Count down
///
Expand All @@ -13,6 +16,9 @@ class CountdownController {
// Called when restarting the timer
VoidCallback onRestart;

// Called when change timer seconds directly
IntCallback onSetTimer;

///
/// Checks if the timer is running and enables you to take actions according to that.
/// if the timer is still active, `isCompleted` returns `false` and vice versa.
Expand Down Expand Up @@ -68,4 +74,17 @@ class CountdownController {
setOnRestart(VoidCallback onRestart) {
this.onRestart = onRestart;
}

///
/// Set timer seconds
///
setTimer(int seconds) {
if (this.onSetTimer != null) {
this.onSetTimer(seconds);
}
}

setOnSetTimer(IntCallback onSetTimer) {
this.onSetTimer = onSetTimer;
}
}
13 changes: 13 additions & 0 deletions lib/timer_count_down.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
// Dart libs
import 'dart:async';

// Flutter libs
import 'package:flutter/widgets.dart';

// Local deps
import 'package:timer_count_down/timer_controller.dart';

///
Expand Down Expand Up @@ -56,6 +59,8 @@ class _CountdownState extends State<Countdown> {
widget.controller?.setOnPause(_onTimerPaused);
widget.controller?.setOnResume(_onTimerResumed);
widget.controller?.setOnRestart(_onTimerRestart);
widget.controller?.setOnSetTimer(_onSetTimer);

widget.controller?.isCompleted = false;

_startTimer();
Expand Down Expand Up @@ -109,6 +114,14 @@ class _CountdownState extends State<Countdown> {
_startTimer();
}

void _onSetTimer(int seconds) {
print('Timer set to $seconds');

setState(() {
_currentMicroSeconds = seconds * _secondsFactor;
});
}

///
/// Start timer
///
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: timer_count_down

version: 1.0.4+1
version: 1.0.5

description: >
Simple CountDown timer. Using for create a simple timer. It's pure all
Expand Down