Sitelet https://web.archive.org/web/20220822051240/https://github.com/federicodesia/custom_timer
Skip to content

federicodesia/custom_timer

master
Switch branches/tags
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
 
 
lib
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

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.2

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

About

A Flutter package to create a customizable timer.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages