Flutter中的Timer
1.单次运行的定时器
- 源码:
factory Timer(Duration duration, void Function() callback) {
if (Zone.current == Zone.root) {
// No need to bind the callback. We know that the root's timer will
// be invoked in the root zone.
return Zone.current.createTimer(duration, callback);
}
return Zone.current
.createTimer(duration, Zone.current.bindCallbackGuarded(callback));
}
- 示例代码:

本文介绍了Flutter中Timer类的使用方法,包括单次运行的定时器和重复运行定时器的创建及取消方式。通过示例代码展示了如何设置不同类型的定时任务。
最低0.47元/天 解锁文章
6654

被折叠的 条评论
为什么被折叠?



