Custom Timer ⌛

A Flutter package to create a customizable timer.


🎉 Features

  • Timer controller.
  • Auto count up / down timer.
  • Custom builders.

📌 Simple Usage


example1


final CustomTimerController _controller = CustomTimerController();
CustomTimer(
  controller: _controller,
  begin: Duration(days: 1),
  end: Duration(),
  builder: (time) {
    return Text(
      "${time.hours}:${time.minutes}:${time.seconds}.${time.milliseconds}",
      style: TextStyle(fontSize: 24.0)
    );
  }
)

Now you can use the controller methods start(), pause() and reset(). You can also add listeners to state changes or just use the state property when you need it.


📌 Using StateBuilder and AnimationBuilder


example2


CustomTimer(
  controller: _controller,
  begin: Duration(days: 1),
  end: Duration(),
  builder: (time) {
    return Text(
      "${time.hours}:${time.minutes}:${time.seconds}.${time.milliseconds}",
      style: TextStyle(fontSize: 24.0)
    );
  },
  stateBuilder: (time, state) {
    // This builder is shown when the state is different from "couting".
    if(state == CustomTimerState.paused) return Text(
      "The timer is paused",
      style: TextStyle(fontSize: 24.0)
    );

    // If null is returned, "builder" is displayed.
    return null;
  },
  animationBuilder: (child) {
    // You can define your own state change animations.
    // Remember to return the child widget of the builder.
    return AnimatedSwitcher(
      duration: Duration(milliseconds: 250),
      child: child,
    );
  },
  onChangeState: (state){
    // This callback function runs when the timer state changes.
    print("Current state: $state");
  }
)

🔧 Installation

Add this to your package's pubspec.yaml file:

dependencies:
  custom_timer: ^0.1.1

Install it:

$ flutter pub get

Import the package in your project:

import 'package:custom_timer/custom_timer.dart';

🙇 Author


Hi there 👋 This package is in development so if you find a bug or have a suggestion please let me know so we can improve it! 😃 If you want to motivate me to continue, you can give me a cup of coffee ☕ and I will get a lot of energy out of it.


Buy Me A Coffee

Libraries

custom_timer
CustomTimer package.