TimerUtils class
TimerUtils —— 通用定时器 / 倒计时工具。
提供 startTimer(周期定时)与 startCountDown(倒计时)两种模式;
倒计时基于启动时固定的 endTime 墙钟,避免 Timer.periodic 漂移。
不再使用时请调用 cancel / dispose 释放底层 Timer。
Constructors
- TimerUtils({int mInterval = Duration.millisecondsPerSecond, int mTotalTime = 0})
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- mInterval ↔ int
-
Timer interval (unit millisecond,def: 1000 millisecond).
Timer间隔 单位毫秒,默认1000毫秒(1秒).
getter/setter pair
- mTotalTime ↔ int
-
countdown totalTime.
倒计时总时间
getter/setter pair
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
cancel(
) → void - Cancels the timer. 取消计时器.
-
dispose(
) → void - Releases resources by cancelling the underlying Timers.
-
isActive(
) → bool - timer is Active. Timer是否启动.
-
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
restart(
int totalTime) → void - Restart the countdown with a new totalTime.
-
setInterval(
int interval) → void - set Timer interval. (unit millisecond). 设置Timer间隔.
-
setOnTimerTickCallback(
OnTimerTickCallback callback) → void - set timer callback.
-
setTotalTime(
int totalTime) → void - set countdown totalTime. (unit millisecond). 设置倒计时总时间.
-
startCountDown(
) → void - start countdown Timer. 启动倒计时Timer.
-
startTimer(
) → void - start Timer. 启动定时Timer.
-
toString(
) → String -
A string representation of this object.
inherited
-
updateTotalTime(
int totalTime) → void - Update countdown totalTime as a PURE setter.
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited
Static Properties
- now ↔ DateTime Function()
-
可注入的时钟;默认 DateTime.now。测试用
FakeAsync时覆盖它, 使 startCountDown 的墙钟计算可由测试驱动(本测试环境下 FakeAsync 接管 Timer 但不接管DateTime.now())。getter/setter pair