TimerLabelController class
A controller for managing a countdown timer.
The TimerLabelController handles the logic of counting down from a given duration and notifies its listeners every second. It supports pausing, resuming, resetting, and restarting the timer. An optional onTimerEnd callback is invoked when the timer reaches zero.
The timer supports displaying hours. By default, it will automatically include hours in the display if the remaining time is 1 hour or more. You can force hours to always appear by setting alwaysShowHours to true.
- Inheritance
-
- Object
- ChangeNotifier
- TimerLabelController
Constructors
- TimerLabelController({required Duration duration, VoidCallback? onTimerEnd, bool alwaysShowHours = false})
-
Creates a TimerLabelController with the specified
duration.
Properties
- alwaysShowHours → bool
-
Whether to always display the hours field (even when less than one hour).
final
- duration → Duration
-
The initial duration for the countdown.
final
- hashCode → int
-
The hash code for this object.
no setterinherited
- hasListeners → bool
-
Whether any listeners are currently registered.
no setterinherited
- isCompleted → bool
-
Whether the timer has finished counting down.
no setter
- isRunning → bool
-
Whether the timer is currently running.
no setter
- onTimerEnd → VoidCallback?
-
An optional callback invoked when the timer completes.
final
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- secondsRemaining → int
-
Returns the remaining time in seconds.
no setter
- timeRemaining → String
-
Returns the formatted remaining time as a string.
no setter
Methods
-
addListener(
VoidCallback listener) → void -
Register a closure to be called when the object changes.
inherited
-
dispose(
) → void -
Discards any resources used by the object.
override
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
notifyListeners(
) → void -
Call all the registered listeners.
inherited
-
pauseTimer(
) → void - Pauses the countdown timer.
-
removeListener(
VoidCallback listener) → void -
Remove a previously registered closure from the list of closures that are
notified when the object changes.
inherited
-
resetTimer(
) → void - Resets the countdown timer to the initial duration.
-
restartTimer(
) → void - Restarts the countdown timer from the beginning.
-
resumeTimer(
) → void - Resumes the countdown timer from its current remaining time.
-
startTimer(
{Duration? startTime}) → void - Starts the countdown timer.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateSeconds(
int elapsedSeconds) → void - Updates the remaining seconds by subtracting the elapsed time.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited