Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

customizable timer

customizable timer

a highly customizable timer builder, with controller, animation, intervals, callbacks, custom actions, and more!

customizable timer

�� simple usage

customizable timer

@override
  widget build(buildcontext context) {
    return materialapp(
      debugshowcheckedmodebanner: false,
      home: scaffold(
        appbar: appbar(
          title: text("customtimer example"),
        ),
        body: center(
          child: customtimer(
            from: duration(hours: 12),
            to: duration(hours: 0),
            onbuildaction: customtimeraction.auto_start,
            builder: (customtimerremainingtime remaining) {
              return text(
                "${remaining.hours}:${remaining.minutes}:${remaining.seconds}",
                style: textstyle(fontsize: 30.0),
              );
            },
          ),
        ),
      ),
    );
  }

�� custom usage

customizable timer

options that allow for more control:

properties type description
from duration the start of the timer.
to duration the end of the timer.
interval duration the time interval to update the widget.
the default interval is duration(seconds: 1).
controller customtimercontroller controls the state of the timer.
onbuildaction customtimeraction execute an action when the widget is built for the first time.
the default action is customtimeraction.go_to_start.
onfinishaction customtimeraction execute an action when the timer finish.
the default action is customtimeraction.go_to_end.
onresetaction customtimeraction executes an action when the timer is reset.
the default action is customtimeraction.go_to_start.
builder widget function(customtimerremainingtime) function that builds a custom widget and allows to obtain the remaining time of the timer.
finishedbuilder widget function(customtimerremainingtime) function that builds a custom widget and allows to get the remaining time only when the timer has finished.
if you use it, it will replace builder.
pausedbuilder widget function(customtimerremainingtime) function that builds a custom widget and allows to get the remaining time only when the timer is paused.
if you use it, it will replace builder.
resetbuilder widget function(customtimerremainingtime) function that builds a custom widget and allows to get the remaining time only when the timer is reset.
if you use it, it will replace builder.
onstart voidcallback callback function that runs when the timer start.
onfinish voidcallback callback function that runs when the timer finish.
onpaused voidcallback callback function that runs when the timer is paused.
onreset voidcallback callback function that runs when the timer is reset.
onchangestate function(customtimerstate) callback function that runs when the timer state changes. returns a customtimerstate that allows you to get the state and create custom functions or conditions.
onchangestateanimation animatedswitcher animation that runs when the state of the timer changes. it is not necessary to define a child because it will be replaced by the current builder.

customtimeraction actions:

customizable timer

actions description
customtimeraction.go_to_start shows the start of the timer.
customtimeraction.go_to_end shows the end of the timer.
customtimeraction.auto_start automatically starts the timer.

customtimerremainingtime properties:

customizable timer

properties description
days a string with the remaining days.
hours a string with the remaining hours.
hourswithoutfill a string with the remaining hours and only with two digits when necessary.
minutes a string with the minutes remaining.
minuteswithoutfill a string with the remaining minutes and only with two digits when necessary.
seconds a string with the seconds remaining.
secondswithoutfill a string with the remaining seconds and only with two digits when necessary.
milliseconds a string with the remaining milliseconds.
duration a default duration with remaining time.
lets you create more specific functions or conditions, but remember that it can return more than 59 minutes and seconds and more than 1000 milliseconds.

customtimerstate states:

customizable timer

states
customtimerstate.reset
customtimerstate.counting
customtimerstate.paused
customtimerstate.finished

you can access the timer state from the onchangestate callback function or using a customtimercontroller.

for example:

customtimerstate state = _controller.state;

�� using the customtimercontroller

  final customtimercontroller _controller = new customtimercontroller();

  @override
  widget build(buildcontext context) {
    return materialapp(
      debugshowcheckedmodebanner: false,
      home: scaffold(
        appbar: appbar(
          title: text("customtimer example"),
        ),
        body: column(
          mainaxisalignment: mainaxisalignment.center,
          children: <widget>[
            customtimer(
              controller: _controller,
              from: duration(hours: 12),
              to: duration(hours: 0),
              builder: (customtimerremainingtime remaining) {
                return text(
                  "${remaining.hours}:${remaining.minutes}:${remaining.seconds}",
                  style: textstyle(fontsize: 30.0),
                );
              },
            ),
            sizedbox(height: 16.0,),
            row(
              mainaxisalignment: mainaxisalignment.spaceevenly,
              children: [
                flatbutton(
                  child: text("start"),
                  onpressed: () => _controller.start(),
                  color: colors.green,
                ),
                flatbutton(
                  child: text("pause"),
                  onpressed: () => _controller.pause(),
                  color: colors.blue,
                ),
                flatbutton(
                  child: text("reset"),
                  onpressed: () => _controller.reset(),
                  color: colors.red
                ),
              ],
            )
          ],
        ),
      ),
    );
  }

customtimercontroller properties:

properties permissions description
state read returns the current state of the timer.

customtimercontroller methods:

methods description
start() start or resume the timer.
pause() pause the timer.
reset() reset the timer.
if you want to restart the timer, you can call the controller start() method or set the onresetaction property to customtimeraction.auto_start.

⚙️ installation

add this to your package’s pubspec.yaml file:

dependencies:
  custom_timer: ^0.0.2

install it:

$ flutter pub get

import the package in your project:

import 'package:custom_timer/custom_timer.dart';

Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Top