FakeOverlayClock class

同时控制当前时间及单次计时器的确定性时钟,不依赖 Flutter 绑定。 纯 Dart test() 中调用 advance 推进时间,再用 await Future<void>.delayed(Duration.zero) 排空 Future 微任务续体。 例如 clock.advance(const Duration(seconds: 1));pendingTimers 可检查泄漏。

Inheritance

Constructors

FakeOverlayClock([DateTime? start])
从 start 开始,默认 DateTime(2000)。

Properties

hashCode → int
The hash code for this object.
no setterinherited
pendingTimers → int
尚未触发且未取消的计时器数量。
no setter
runtimeType → Type
A representation of the runtime type of the object.
no setterinherited

Methods

advance(Duration d) → void
推进非负时长,依次触发窗口内的计时器,包含回调中新建的计时器。 同时到期按创建顺序触发;负时长抛 ArgumentError,嵌套推进抛 StateError。 回调抛错会向调用方传播,当前时间停在该计时器的到期时刻。
createTimer(Duration duration, void callback()) → Timer
创建单次计时器,返回可取消的 Timer。
override
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
now() → DateTime
返回当前模拟时间。
override
toString() → String
A string representation of this object.
inherited

Operators

operator ==(Object other) → bool
The equality operator.
inherited