TimerWidget class
An interactive countdown timer widget.
It renders a digital clock readout (format "MM:SS") centered in its viewport with an optional graphical progress bar on the line below.
Example Usage
final timer = TimerWidget(
duration: const Duration(minutes: 5),
running: true,
onFinished: () {
print('Time is up!');
},
);
Properties and Settings
| Property | Type | Description |
|---|---|---|
duration |
Duration | The current remaining duration of the countdown. |
initialDuration |
Duration | The starting countdown duration (for progress). |
onFinished |
void Function()? |
Callback triggered when duration reaches zero. |
digitStyle |
Style | Rendering style for the digit characters. |
separatorStyle |
Style | Rendering style for the ':' character. |
progressStyle |
Style | Rendering style for the bottom progress bar. |
running |
bool | Active running/paused state of the timer. |
Constructors
- TimerWidget({required Duration duration, bool running = false, void onFinished()?, Style digitStyle = const Style(foreground: Colors.orange, modifiers: Modifier.bold), Style separatorStyle = const Style(modifiers: Modifier.dim), Style progressStyle = const Style(foreground: Colors.green)})
- Creates a TimerWidget to display a countdown.
Properties
- digitStyle → Style
-
The styling for the digits of the countdown.
final
- duration ↔ Duration
-
The current remaining duration.
getter/setter pair
- hashCode → int
-
The hash code for this object.
no setterinherited
- initialDuration → Duration
-
The initial duration the timer started with.
final
- key → Key?
-
The optional key for this widget.
finalinherited
- onFinished → void Function()?
-
An optional callback executed when the timer finishes.
final
- progressStyle → Style
-
The styling for the progress bar.
final
- running ↔ bool
-
Indicates whether the timer is actively counting down.
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
- separatorStyle → Style
-
The styling for the separator character.
final
Methods
-
createElement(
) → Element -
Creates an Element to manage this widget's location in the tree.
inherited
-
getIntrinsicHeight(
int width) → int -
Computes the intrinsic height of this widget under the given
widthconstraint.inherited -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
render(
Buffer buffer, Rect area) → void -
Renders the widget onto the provided
bufferwithin the specifiedarea.override -
tick(
Duration delta) → void -
Decrements the remaining duration by the specified
deltaamount. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited