norns 0.1.3
norns: ^0.1.3 copied to clipboard
A Framwork for Interval Timer. Run multiple timers sequentially! easy to use, customizable, and with no common time-related bugs.
Norns
A Framework for Interval Timer
🚧 Alpha version - Use with care. 🚧
Norns [ˈnornez̠]
- Goddesses in Norse mythology responsible for shaping the course of human destinies.
- A Framework for Interval Timer that will make your time-management easier.
Features #
- ⏰➞⏰➞⏰➞⏰ Run multiple timers sequentially.
- Customizable. You can set business-specific actions on timers.
- Easy to use. Don't worry about common bugs caused when dealing with time! Just describe your business logic to Norns.
Installing #
dependencies:
norns: ^0.1.2
import 'package:norns/norns.dart';
A simple Pomodoro Console App #
final norns = Norns();
final timerMetadata = {1: 'Pomodoro', 2: 'Break Time'};
final pointMetadata = {1: 'elpased'};
final perOneSeconds = [pointPeriodic(key: 1, point: 1.s, period: 1.s)];
norns.addAllTimers([
timer(key: 1, duration: 5.s, points: perOneSeconds),
timer(key: 2, duration: 2.s, points: perOneSeconds),
]);
norns.setOnPoint((running, point) {
final pointType = point.type.toShortString();
final timerName = timerMetadata[running.key]?.padRight(10) ?? '';
final pointName = pointMetadata[point.key] ?? '';
final elpased = '${point.point - running.startedAt}'.substring(0, 7);
print('[$timerName] [$pointType] $elpased $pointName');
});
norns.resume();
[Pomodoro ] [Timer Start] 0:00:00
[Pomodoro ] [Point] 0:00:01 elpased
[Pomodoro ] [Point] 0:00:02 elpased
[Pomodoro ] [Point] 0:00:03 elpased
[Pomodoro ] [Point] 0:00:04 elpased
[Pomodoro ] [Point] 0:00:05 elpased
[Pomodoro ] [Timer End] 0:00:05
[Break Time] [Timer Start] 0:00:00
[Break Time] [Point] 0:00:01 elpased
[Break Time] [Point] 0:00:02 elpased
[Break Time] [Timer End] 0:00:02
Usage #
addTimerandaddAllTimersadd timers to Nornsresumestarts Nornspausestop Nornsresetinitialize NornsbreakCurrentRunningTimerskip the current running timer.setOnFiresets the onFire callback.setOnTimerChangesets the onTimerChange callback.setOnFinishedsets the onFinished callback.removeOnFireremoves the onFire callbackremoveOnTimerChangeremoves the onTimerChange callback.removeOnFinishedremoves the onFinished callback.
Norns Lifecycle
-
onFire
Called when the first startup.
-
onTimerChange
Called when timers change.
-
onFinished
Called when all timers finished.
-
onPoint
Called when:
-
a timer starts
-
a timer ends
-
a timer broken(skipped)
-
a time-point you set reached. you can set custom time-points with:
-
point
The example below represents that a timer has a duration of 10 seconds and custom time-points of 5 seconds and 7 seconds.
timer( duration: 10.s, points: [ point(point: 5.s), point(point: 7.s) ], );and you can receive the events as follows.
norns.setOnPoint((runningTimer, point) { if (point.isTimerStart) { // do something when a timer starts } if (point.isTimerEnd) { // do something when a timer ends } if (point.isTimerBroken) { // do something when a timer is broken(skipped) } if (point.isPoint) { // user-defined actions here } }); -
pointFromEnd
Maybe you want to set an action like 1 seconds left. The example below represents that a timer has a duration of 10 seconds and the custom time-point 9 seconds.
timer( duration: 10.s, points: [ pointFromEnd(point: 1.s), ], ); -
pointPeriodic
Time-points that run periodically.
timer( duration: 10.s, points: [ pointPeriodic(point: 1.s, period: 1.s), ], );
-