Git Product home page Git Product logo

circular_countdown_timer's Introduction

Circular Countdown Timer

Make an animated circular countdown using Circular Countdown Timer.

Getting Started

To use this plugin, add circular_countdown_timer as a dependency in your pubspec.yaml file.

Features

  • Forward Countdown Timer.
  • Reverse Countdown Timer.
  • Start, Pause, Resume, Restart and Reset Timer.

Usage

CircularCountDownTimer(
     duration: 10,
     initialDuration: 0,
     controller: CountDownController(),
     width: MediaQuery.of(context).size.width / 2,
     height: MediaQuery.of(context).size.height / 2,
     ringColor: Colors.grey[300]!,
     ringGradient: null,
     fillColor: Colors.purpleAccent[100]!,
     fillGradient: null,
     backgroundColor: Colors.purple[500],
     backgroundGradient: null,
     strokeWidth: 20.0,
     strokeCap: StrokeCap.round,
     textStyle: TextStyle(
         fontSize: 33.0, color: Colors.white, fontWeight: FontWeight.bold),
     textAlign: TextAlign.center,
     textFormat: CountdownTextFormat.S,
     isReverse: false,
     isReverseAnimation: false,
     isTimerTextShown: true,
     autoStart: false,
     onStart: () {
        debugPrint('Countdown Started');
     },
     onComplete: () {
        debugPrint('Countdown Ended');
     },
     onChange: (String timeStamp) {
        debugPrint('Countdown Changed $timeStamp');
     },
     timeFormatterFunction: (defaultFormatterFunction, duration) {
        if (duration.inSeconds == 0) {
           return "Start";
        } else {
           return Function.apply(defaultFormatterFunction, [duration]);
        }
     },
 );

Parameters

Name Type Default Value Description
key Key null Key for Countdown Timer.
duration int null Countdown duration in Seconds.
initialDuration int 0 Countdown initial elapsed Duration in Seconds.
controller CountDownController null Controls (i.e Start, Pause, Resume, Restart) the Countdown Timer.
width double null Width of the Countdown Widget.
height double null Height of the Countdown Widget.
ringColor Color null Ring Color for Countdown Widget.
ringGradient Gradient null Ring Gradient for Countdown Widget. Note that ringColor will not be effective if gradient is provided.
fillColor Color null Filling Color for Countdown Widget.
fillGradient Gradient null Filling Gradient for Countdown Widget. Note that fillColor will not be effective if gradient is provided.
backgroundColor Color null Background Color for Countdown Widget.
backgroundGradient Gradient null Background Gradient for Countdown Widget. Note that backgroundColor will not be effective if gradient is provided.
strokeWidth double 5.0 Border Thickness of the Countdown Ring.
strokeCap StrokeCap StrokeCap.butt Begin and end contours with a flat edge and no extension.
textStyle TextStyle TextStyle(fontSize: 16.0,color: Colors.black,) Text Style for Countdown Text.
textFormat String null Format for the Countdown Text.
isReverse bool false Handles Countdown Timer (true for Reverse Countdown (max to 0), false for Forward Countdown (0 to max)).
isReverseAnimation bool false Handles Animation Direction (true for Reverse Animation, false for Forward Animation).
isTimerTextShown bool true Handles visibility of the Countdown Text.
autoStart bool true Handles the timer start.
onStart VoidCallback null This Callback will execute when the Countdown Starts.
onComplete VoidCallback null This Callback will execute when the Countdown Ends.
onChange ValueChanged<String> null This Callback will execute when the Countdown Changes.
timeFormatterFunction Function(Function(Duration duration) defaultFormatterFunction,Duration duration) null This Callback allows you to format the current duration to any String in Countdown Widget.

Demo

demo

Youtube

Bekar Programmer

Buy Me A Coffee

circular_countdown_timer's People

Contributors

catalin-bratu avatar ceranco avatar duyhungtnn avatar flawnn avatar joshuadeguzman avatar muhammadusamasiddiqui avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

circular_countdown_timer's Issues

hello

pls add in text format package format mm
tnks for great package

Circular countdown timer restricted to 3.0.0 and does not support higher versions of flutter

Using flutter version 3.3.10 doesn't work on circular_countdown_timer. Getting the error below.

Because circular_countdown_timer 0.2.3 requires Flutter SDK version >=1.17.0 and no versions of circular_countdown_timer match >0.2.3 <0.3.0, circular_countdown_timer ^0.2.3 is forbidden. So, because yourProject depends on circular_countdown_timer ^0.2.3, version solving failed.

Could the environment sdk be upgraded to support 3.3.10 ?

Feature Request: Access Current Time While Timer Running

Hello,
I love what you have done with this circular countdown timer, but just wanted to make more of a feature request than an issue. I was wondering if I can take the exact time in the middle of the timer? An example of this is when I move to another screen but I would like to take the exact time left/used in the timer to the next screen by setting the current time to a variable. I would love if this could be implemented into the package!

Thanks,
Rhino773 :)

Flutter duration in seconds does not work?

Hi!
I am in the process of making a timer for my app. Logically, you should be able to choose how long the timer should go. For this I use the Duration() class, but when I pass the set duration from the selector of my duration, at which the timer should start, the timer does not start.

My code is as follows:

CountDownController _countDownController = CountDownController();
Duration _duration = Duration();

 @override
 Widget build(BuildContext context) {
   return Scaffold(
     body: Center(
       child: Column(
         children: [
           CircularCountDownTimer(
             autoStart: false,
             controller: _countDownController,
             isReverse: true,
             duration: _duration.inSeconds,
             fillColor: Colors.purple,
             color: Colors.grey,
             width: MediaQuery.of(context).size.width * 0.5,
             height: MediaQuery.of(context).size.width * 0.5,
           ),
           SizedBox(
             height: MediaQuery.of(context).size.height * 0.3,
             child: CupertinoTimerPicker(
               initialTimerDuration: _duration,
               onTimerDurationChanged: (duration) {
                 setState(() {
                   _duration = duration;
                 });
               },
             ),
           ),
           RaisedButton(
             child: Text('Start Timer'),
             onPressed: () {
               _countDownController.start;
             },
           )
         ],
       ),
     ),
   );
 }```

PS: I use the version 0.0.9, because the 0.1.0 does not work for me when I run "flutter pub get".

Initial value when isReversed: true shouldn't be 0

The timer value shows 0 (or 00:00 or 0:00:00) both when the timer counts up and when it counts down.

This makes sense when counting up (isReversed: false), but when counting down (isReversed: true) it would be nice to start at the value that duration is set to, or maybe even just allow for it to be customized with something else (maybe custom text or something).

Feature Request: Add onChange event

Hi how are you? how to add onChange functionality to return the current second /minute/hour? it would be good because it would help trigger other events according to the current time shown.

Feature Request : Countdown Text Format

Hey!

It would be great to provide a possibility to change the countdown text format. For example, my app requires just a number of seconds to display rather than a 0:04 etc.

I can implement it if you don't mind.

Feature Request: Control the start of countdown

Hi I been wondering if how can I control the start of countdown for example I wish to click a button first before starting countdown, is it possible? Thank you so much! Very nice package.

CountDown timer not working on the background state of App

I have a workout app that plays different exercises and some beep and tts onChange condition. So whenever the app goes on background timer stop working even not restarted in the background. Kindly help me to solve this problem. Thank you

What is the status of the package waiting when autoStart is false?

Your package has helped me a lot with my app, but I have a question.

  1. I specified a time on the main page and made it so that when a button is pressed, the specified time is passed to the timer page. I made the autoStart is false, and to make the timer work when onTap, I added
_TimerController.isStarted.value == true
        // ? _TimerController.resume()
        // : _TimerController.pause();

but it didn't work, so for debugging I checked the values of isPaused, isResume, isStarted, and isRestarted and they all came out false.
I want to make the above code work, please let me know what state the package is waiting in when autoStart is false.

  1. When the time value is above 60, I get minutes and seconds separately, is there any way to make it just seconds?

Change duration from int to Duration

CircularCountDownTimer(duration: 5)
to
CircularCountDownTimer(duration: Duration(seconds: 5))

We can improve the code by changing the duration parameter from int in seconds to Duration.

animation dispose not proper

โ•โ•โ•โ•โ•โ•โ•โ• Exception caught by gesture โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•โ•
The following assertion was thrown while handling a gesture:
AnimationController.stop() called after AnimationController.dispose()
AnimationController methods should not be used after calling dispose.
'package:flutter/src/animation/animation_controller.dart':
animation_controller.dart:1
Failed assertion: line 779 pos 7: '_ticker != null'

getting this error when try to navigate to next screen

CountDownController needs to report current status

Need to be able to get CountDownController.isAnimating (isPaused etc.) or something similar to be able to build adaptive widgets that change based on animation status.

Something similar could also be achieved by setting a variable like timerRunning on start, but this package also doesn't allow you to setState in onStart. It also doesn't allow you to do controller.start() in initState.

These limitations seem fairly severe.

Level of timer

How can I save the level of the circular progress bar? for example if i change the activity while using the app
Thanks you

Implement Pause/Start Button

This issue proposes adding an optional pause/resume button embedded within the timer ring itself. Users can enable or disable this functionality based on their preference

Functionality:

  • A small pause/resume button will be positioned discreetly within the timer ring.
  • When enabled (user configurable option):
    • Clicking the button will pause the timer. The elapsed time will be displayed on the timer, and it will stop counting up/down.
    • Clicking the button again will resume the timer from the paused time.
  • When disabled, the timer ring will function as usual without the button

Benefits:

  • Provides users with the option to pause the timer conveniently without leaving the timer interface.
  • Maintains a clean interface by keeping the button optional.
  • Improves user experience and control over the timer.
Simulator.Screen.Recording.-.iPhone.15.Pro.Max.-.2024-05-04.at.18.05.56.mp4

Attached Prototype Video:

A prototype video showcasing the proposed pause/resume button functionality within the timer ring is included with this issue. This video demonstrates:

  • The visual design and placement of the button within the timer ring.
  • How the button interacts with the timer (pause, resume, user configuration).
  • Overall user experience with the pause/resume functionality.

Change the timer duration

Good night,
I'm making a pomodoro app and I'm having trouble changing the timer duration value. It reads only the first set value. Thank you ;)

onChange Event not working

I run the example code. No Countdown Changed messge printed.

โฏ flutter --version
Flutter 3.10.4 โ€ข channel stable โ€ข https://github.com/flutter/flutter.git
Framework โ€ข revision 682aa387cf (3 days ago) โ€ข 2023-06-05 18:04:56 -0500
Engine โ€ข revision 2a3401c9bb
Tools โ€ข Dart 3.0.3 โ€ข DevTools 2.23.1

Change Time but i want to start the countdown later

I have the same problem like #12 but i don't want to start the timer with the new value.
restart( duration: seconds) starts the timer immediately.
But i want to change the duration and let the user start the timer from a button.

Allow timer to hide the text when not needed

Currently, I don't need the text in the timer but I'm force to add the TextStyle with a color value of Colors.transparent just to hide it from this widget.

Action item:

  • Add a bool flag to hide the text when not needed

timer duration does not change when feeding duration using TextField.

timer duration always takes the 1st value from the TextField even when we change the value from TextField.
Code:

`
import 'package:circular_countdown_timer/circular_countdown_timer.dart';
import 'package:flutter/material.dart';
// import 'package:get/get.dart';

class Testing extends StatefulWidget {
@OverRide
_TestingState createState() => _TestingState();
}

class _TestingState extends State {
CountDownController _controller = CountDownController();
TextEditingController timeTextCtrl = TextEditingController();
@OverRide
void initState() {
super.initState();
timeTextCtrl.text = 50.toString();
}

@OverRide
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
// shrinkWrap: true,
// width: 360,
// height: 640,
// color: Colors.white,
children: [
Center(
child: CircularCountDownTimer(
// Countdown duration in Seconds.
duration: int.parse(timeTextCtrl.text),

          // Countdown initial elapsed Duration in Seconds.
          initialDuration: 0,

          // Controls (i.e Start, Pause, Resume, Restart) the Countdown Timer.
          controller: _controller,

          // Width of the Countdown Widget.
          width: MediaQuery.of(context).size.width / 2,

          // Height of the Countdown Widget.
          height: MediaQuery.of(context).size.height / 2,

          // Ring Color for Countdown Widget.
          ringColor: Colors.grey[300],

          // Ring Gradient for Countdown Widget.
          ringGradient: null,

          // Filling Color for Countdown Widget.
          fillColor: Colors.purpleAccent[100],

          // Filling Gradient for Countdown Widget.
          fillGradient: null,

          // Background Color for Countdown Widget.
          backgroundColor: Colors.purple[500],

          // Background Gradient for Countdown Widget.
          backgroundGradient: null,

          // Border Thickness of the Countdown Ring.
          strokeWidth: 20.0,

          // Begin and end contours with a flat edge and no extension.
          strokeCap: StrokeCap.round,

          // Text Style for Countdown Text.
          textStyle: TextStyle(
              fontSize: 33.0,
              color: Colors.white,
              fontWeight: FontWeight.bold),

          // Format for the Countdown Text.
          textFormat: CountdownTextFormat.S,

          // Handles Countdown Timer (true for Reverse Countdown (max to 0), false for Forward Countdown (0 to max)).
          isReverse: true,

          // Handles Animation Direction (true for Reverse Animation, false for Forward Animation).
          isReverseAnimation: true,

          // Handles visibility of the Countdown Text.
          isTimerTextShown: true,

          // Handles the timer start.
          autoStart: false,

          // This Callback will execute when the Countdown Starts.
          onStart: () {
            // Here, do whatever you want
            print('Countdown Started');
          },

          // This Callback will execute when the Countdown Ends.
          onComplete: () {
            // Here, do whatever you want
            print('Countdown Ended');
          },
        ),
      ),
      TextField(
        controller: timeTextCtrl,
      ),

      ElevatedButton(
        onPressed: () {
          setState(() {
            _controller.start();
          });
        },
        child: Text("Start"),
      ), ],
  ),
);

}
}
`

eg. In the initState we feed the timeTextCtrl.text =50. now if we hit the start button, timer starts from 50 but if we change value of timeTextCtrl.text with let's say 15, and hit the start button, timer starts from 50 only. It should start form 15.
Any Idea how can I achieve this?
Help Please!

onComplete function is not execute when I go to another screen

I'm trying to restart the timer and hit API in the onComplete function.

The above scenario works fine when I stop at the same screen where I implemented the countdown timer, but a similar scenario fails when I go to another screen.

Please let me know ASAP as I have an urgency.

Thanks in advance!!!

Steps to Reproduce:

Go to screen X where the countdown timer is implemented.
Start the countdown timer.
Navigate to screen Y and wait until the countdown is over.
Go to screen X and you'll see the timer hit again when you reach to screen X.

Expected Behavior:

onComplete methods need to work as well when the user is on another screen.

Actual Behavior:

onComplete function is not invoking when the user is on another screen.

onComplete: () async{ _homeBloc.setIsLoading(true); await _homeBloc.getPendingOrders(); _controller.restart(); },

Parameter duration could be a Duration instead an int.

The parameter duration, currently an int, could be a Duration. This modification will help for different types of Duration.

/// Countdown duration in Seconds.
final int duration;

/// Countdown duration.
final Duration duration;

Have any way to localise the timer text?

Thanks a lot for your awesome package.
My App has multi language support (English and Bengali). Have any way to show the count down timer text in Bengali digit? (เงฆ เงง เงจ เงฉ เงช เงซ เงฌ เงญ เงฎ เงฏ)?
Any suggestion for customisation or hack way will be appretiated.
Thanks again.

Reverse countdown but not direction

Can the countdown timer be reversed (from Max to 0) but the direction not be reversed?
As in, when 'isReversed' is true, can the countdown timer continue to go in a clockwise direction (instead of the currently anti-clockwise direction).

AutoStart=false and initialDuration issue

When I set AutoStart=false, it causes the timer to not start from its initialDuration when I start the timer. Instead, It starts from 0.
I would be so grateful if you fix this issue.

New CountDownTextFormat added

Hi there i could not found hours, just min and day type for the code.So i changed package a little bit.
Here is the code that i change:
class CountdownTextFormat {
static const String HH_MM_SS = "HH:mm:ss";
static const String HH = "HH";
static const String DD = "DD";
static const String MM = "mm";
static const String MM_SS = "mm:ss";
static const String SS = "ss";
static const String S = "s";
}
String _getTime(Duration duration) {
// For HH:mm:ss format
if (widget.textFormat == CountdownTextFormat.HH_MM_SS) {
return '${duration.inHours.toString().padLeft(2, '0')}:${(duration.inMinutes % 60).toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
}
// For mm:ss format
else if (widget.textFormat == CountdownTextFormat.MM_SS) {
return '${(duration.inMinutes % 60).toString().padLeft(2, '0')}:${(duration.inSeconds % 60).toString().padLeft(2, '0')}';
} else if (widget.textFormat == CountdownTextFormat.DD) {
return '${(duration.inDays)}';
} else if (widget.textFormat == CountdownTextFormat.HH) {
return '${duration.inHours.toString().padLeft(2, '0')}';
} else if (widget.textFormat == CountdownTextFormat.MM) {
return '${(duration.inMinutes % 60).toString().padLeft(2, '0')}';
}
// For ss format
else if (widget.textFormat == CountdownTextFormat.SS) {
return '${(duration.inSeconds).toString().padLeft(2, '0')}';
}
// For s format
else if (widget.textFormat == CountdownTextFormat.S) {
return '${(duration.inSeconds)}';
} else {
// Default format
return _defaultFormat(duration);
}
}
if you want you can update the package.Thank you for your package it helps a lot.

Countdown restart doesnt work in background

I start the countdown with 10 seconds, then lock the screen or go to background. When the onComplete function of the countdown is triggered I have a function that use the method restart(duration: 15) of the controller of the countdown. The problem is that the countdown only get restarted when I open the app again, it doesn't get restarted in backgound or with the screen locked.

Analysis Issue in v.0.2.4

I cannot upgrade this version no 0.2.4 because of analysis issue in pub.dev.
Please fix this issue and send a new update in pub.dev.

repo in development?

Hi @flawnn,

i have seen, that you merged some pull requests some two days ago. I thought this repo is dead because the last release was 2 years ago, so i forked it and added some features like reset without autostart and changing duration. I extracted the countdown Controller to a separate file, too.

My question is, will your repo be in development in the future, or should a go on with my fork?

Kind Regards
Trashcoder

Customize text

Hello! Thanks for writing such great extension.

I was wondering whether you could add a feature that I can customize the text during count down (in the center of the circle)?

Thank you again!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.