support@codebucket.net

How To Add A Countdown Timer In A Flutter Project

How To Add A Countdown Timer In A Flutter Project

Nafis Hasrat Arnob | January 16, 2023

Hello Developers,

 

Countdown Timer is a unique feature of a flutter application. In this lesson, we will learn how to add a countdown timer to a flutter project. Let's begin.
 

 

Flutter App Installation

 

 

Open the android studio and create a fresh Flutter project like below:

 

 

 

 

Give a name like test_app in the android studio.

 

 

 

Package Added To The Project

 

If we need to show a countdown timer in the app we have a powerful package and the best part is this package is very easy to implement. The name of the package is flutter_countdown_time. The current version of this widget is 4.1.0. Let’s see how to implement this widget into our flutter project.

 

Firstly, we have to add this package in pubspec.yaml file like this:

 

dependencies:
    flutter_countdown_timer: ^4.1.0

 

Or we can simply install this package with this command:

 

flutter pub add flutter_countdown_timer

 

Then, we need to install this widget using this command:

 

flutter pub get

 

Package Configuration

 

Then, we need to declare a variable to store the end time of the countdown timer in the mian.dart file:

 

int endTime = DateTime.now().millisecondsSinceEpoch + 1000 * {seconds to be counted};

 

After that, we can call this widget:

 

CountdownTimer(
  endTime: endTime,
  textStyle: const TextStyle(
    color: Colors.green,
    fontSize: 30,
  ),
  onEnd: () {
    print('Timer ended');
  },
),

 

If we run the project then the output will look like this:

 

 

Hope this tutorial might help in the journey of your development

 

Read More: How To Use Image In A Flutter Project

 

Nafis Hasrat Arnob

Nafis Hasrat Arnob

Information Analyst

I am a Flutter developer working for a reputed company in Bangladesh. I am trying my best to gain proficiency in Software Development. I am also interested in Artificial Intelligence, Machine Learning, and Computer Vision.