custom_timer 0.1.2 copy "custom_timer: ^0.1.2" to clipboard
custom_timer: ^0.1.2 copied to clipboard

outdated

A Flutter package to create a customizable timer with controller.

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
146
likes
0
points
3.89k
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package to create a customizable timer with controller.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on custom_timer