如何yield从 a 的重复回调中获取状态Timer?
我的类中有一个 Timer 对象,当用户点击开始时,会创建它的一个新对象,并且在它的回调中我需要调用yield ....
这是我到目前为止的代码,但它没有做任何事情:
if (event is CounterETimerStart) {
timer = Timer.periodic(Duration(seconds: 1), (timer) async* {
yield CounterNewSecond(++m.passedTime);
});
}
Run Code Online (Sandbox Code Playgroud)
在 github 的 @RollyPeres 的帮助下,这是一种方法:
您可以添加事件并对其做出反应。
if (event is CounterETimerStart) {
timer = Timer.periodic(Duration(seconds: 1), (timer) {
add(TimerTicked());
});
}
if (event is TimerTicked) {
yield CounterNewSecond(++m.passedTime);
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1411 次 |
| 最近记录: |