flutter_smart_timer 1.1.6
flutter_smart_timer: ^1.1.6 copied to clipboard
A smart timer designed for easy use, featuring interval functions and customizable duration settings.
SmartTimer π #
SmartTimer is a powerful and flexible library on Dart for working with timers. It supports countdown, intervals, custom durations, and event notifications via streams. It is ideal for creating timers in Dart and Flutter applications.
The possibilities π #
π Timer with intervals: Specify the intervals at which events will be triggered.
β³ Countdown: Support for countdown timers.
β±οΈ Custom duration: Set your own duration for each tick.
π Streams: Receive notifications about ticks, intervals, and completion via Stream.
β―οΈ Pause and Resume: Control the timer with pause and resume.
π Easy to use: A simple and intuitive API.
Installation π¦ #
Add the dependency to your pubspec.yaml:
dependencies:
smart_timer: ^1.1.6
Then run:
dart pub get
Use π #
A simple timer:
import 'package:smart_timer/smart_timer.dart';
void main() {
final timer = SmartTimer(
endTime: 10,
countDown: false,
intervals: [5, 10],
onTick: (time) => print('Tick: $time'),
onIntervalTick: (time) => print('Interval: $time'),
onComplete: (time) => print('Completed!'),
);
timer.start();
}
The countdown
final timer = SmartTimer(
endTime: 0,
countDown: true,
countDownStartedTime: Duration(seconds: 60),
intervals: [30, 0],
onTick: (time) => print('Tick: $time'),
onComplete: (time) => print('Time\'s up!'),
);
timer.start();
Streams
timer.onTick.listen((duration) {
print('Current time: ${duration.inSeconds}');
});
timer.onComplete.listen((duration) {
print('Timer completed at ${duration.inSeconds} seconds');
});
API π #
Basic methods #
start(): Starts the timer.
pause(): Pauses the timer.
resume(): Resumes the timer.
stop(): Stops the timer and resets the time.
dispose(): Closes all threads and releases resources.
Properties #
currentTime : The current timer time.
isActive: Returns true if the timer is active.
onTick: A thread for tick events.
onInterval: A stream for interval events.
onComplete: The thread for the completion event.
Support π€ #
If you have any suggestions or have found a bug, please create an issue. We also welcome your Pull Request!
License π #
This project is distributed under the MIT license. For more information, see the LICENSE file.
Author π¨π» #
Designed with https://github.com/Anykeykin