0 purchases
custom timer
Custom Timer ⌛ #
A Flutter package to create a customizable timer.
🎉 Features #
Timer controller.
Auto count up / down timer.
Custom builder.
Millisecond support.
📌 Usage #
Add SingleTickerProviderStateMixin to your stateful widget. 👇
class _MyAppState extends State<MyApp> with SingleTickerProviderStateMixin {
copied to clipboard
Then define a CustomTimer controller
late CustomTimerController _controller = CustomTimerController(
vsync: this,
begin: Duration(hours: 24),
end: Duration(),
initialState: CustomTimerState.reset,
interval: CustomTimerInterval.milliseconds
);
copied to clipboard
And you are ready to use the timer:
CustomTimer(
controller: _controller,
builder: (state, time) {
// Build the widget you want!🎉
return Text(
"${time.hours}:${time.minutes}:${time.seconds}.${time.milliseconds}",
style: TextStyle(fontSize: 24.0)
);
}
)
copied to clipboard
Now you can use the controller methods:
_controller.reset();
_controller.start();
_controller.pause();
_controller.finish();
_controller.add(Duration(minutes: 30));
_controller.subtract(Duration(minutes: 30));
_controller.jumpTo(Duration(hours: 12));
copied to clipboard
You can also set the begin or end, even with the counter running:
_controller.begin = Duration();
_controller.end = Duration(hours 12);
copied to clipboard
And add listeners to state changes or just use the properties when you need them:
_controller.state.addListener(() {
print(_controller.state.value); // 👉 CustomTimerState.paused
print(_controller.remaining.value.hours); // 👉 12h
});
copied to clipboard
Remember to dispose when you are no longer using it.
🔧 Installation #
Add this to your package's pubspec.yaml file:
dependencies:
custom_timer: ^0.2.3
copied to clipboard
Install it:
$ flutter pub get
copied to clipboard
Import the package in your project:
import 'package:custom_timer/custom_timer.dart';
copied to clipboard
🙇 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.
For personal and professional use. You cannot resell or redistribute these repositories in their original state.
There are no reviews.