diff --git a/CHANGELOG.md b/CHANGELOG.md index d25ccfc..0fe93f8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/example/android/app/build.gradle b/example/android/app/build.gradle index 0f6a5e5..1cdba7f 100644 --- a/example/android/app/build.gradle +++ b/example/android/app/build.gradle @@ -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' @@ -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 { @@ -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' } diff --git a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt index 1656503..5b736d4 100644 --- a/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt +++ b/example/android/app/src/main/kotlin/com/example/example/MainActivity.kt @@ -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); - } } diff --git a/example/android/build.gradle b/example/android/build.gradle index 3100ad2..5db2af7 100644 --- a/example/android/build.gradle +++ b/example/android/build.gradle @@ -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" } } diff --git a/example/android/gradle/wrapper/gradle-wrapper.properties b/example/android/gradle/wrapper/gradle-wrapper.properties index 296b146..da44bc1 100644 --- a/example/android/gradle/wrapper/gradle-wrapper.properties +++ b/example/android/gradle/wrapper/gradle-wrapper.properties @@ -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 diff --git a/example/lib/main.dart b/example/lib/main.dart index 5b2135e..4545093 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -45,7 +45,7 @@ class MyHomePage extends StatefulWidget { /// Page state /// class _MyHomePageState extends State { - final CountdownController controller = CountdownController(); + final CountdownController _controller = CountdownController(); bool _isPause = true; bool _isRestart = false; @@ -63,33 +63,63 @@ class _MyHomePageState extends State { ), ), 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: [ + 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: [ + 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) { diff --git a/lib/timer_controller.dart b/lib/timer_controller.dart index 264a692..ab3f32e 100644 --- a/lib/timer_controller.dart +++ b/lib/timer_controller.dart @@ -1,5 +1,8 @@ +// Flutter libs import 'package:flutter/widgets.dart'; +typedef IntCallback = Function(int value); + /// /// Controller for Count down /// @@ -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. @@ -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; + } } diff --git a/lib/timer_count_down.dart b/lib/timer_count_down.dart index 4d3d089..5eb0961 100644 --- a/lib/timer_count_down.dart +++ b/lib/timer_count_down.dart @@ -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'; /// @@ -56,6 +59,8 @@ class _CountdownState extends State { widget.controller?.setOnPause(_onTimerPaused); widget.controller?.setOnResume(_onTimerResumed); widget.controller?.setOnRestart(_onTimerRestart); + widget.controller?.setOnSetTimer(_onSetTimer); + widget.controller?.isCompleted = false; _startTimer(); @@ -109,6 +114,14 @@ class _CountdownState extends State { _startTimer(); } + void _onSetTimer(int seconds) { + print('Timer set to $seconds'); + + setState(() { + _currentMicroSeconds = seconds * _secondsFactor; + }); + } + /// /// Start timer /// diff --git a/pubspec.yaml b/pubspec.yaml index b1837f0..a7a3919 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -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