TimerModel class
A countdown timer model.
The timer counts down from timeout duration, ticking at interval
intervals. When the timer reaches zero, it sends a TimerTickMsg with
timeout: true.
Example:
final timer = TimerModel(timeout: Duration(seconds: 30));
final (model, cmd) = timer.init();
// Start the timer
final (model2, cmd2) = model.update(TimerStartStopMsg(true, model.tag));
- Inheritance
-
- Object
- Model
- ViewComponent
- TimerModel
Constructors
- TimerModel({required Duration timeout, Duration interval = const Duration(seconds: 1)})
- Creates a new timer model.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- id → int
-
Returns the internal ID for this timer.
no setter
- interval → Duration
-
How often the timer ticks.
final
- running → bool
-
Returns whether the timer is currently running.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- tag → int
-
Returns the tag for this timer instance.
no setter
- timedOut → bool
-
Returns whether the timer has timed out (timeout <= 0).
no setter
- timeout → Duration
-
The duration to count down from.
final
Methods
-
copyWith(
{Duration? timeout, Duration? interval, bool? running, int? id, int? tag}) → TimerModel - Creates a copy of this model with the given fields replaced.
-
init(
) → Cmd? -
Initializes the timer.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
start(
) → Cmd - Creates a command to start the timer.
-
stop(
) → Cmd - Creates a command to stop the timer.
-
toggle(
) → Cmd - Creates a command to toggle the timer on/off.
-
toString(
) → String -
A string representation of this object.
inherited
-
update(
Msg msg) → (TimerModel, Cmd?) -
Updates the timer based on incoming messages.
override
-
view(
) → String -
Returns the view of the timer.
override
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited