简体   繁体   English

定时器后飞镖/颤振产量 state

[英]Dart/Flutter Yield state after timer

I am using flutter_bloc and I am not sure how to yield state from within a callback.我正在使用flutter_bloc ,但我不确定如何从回调中产生 state。 Am trying to start timer and return a new state after a pause.我正在尝试启动计时器并在暂停后返回一个新的 state。 Reason I am using a timer is to get the ability to cancel previous timer so it always returns a new state after an idle state.我使用计时器的原因是为了能够取消前一个计时器,因此它总是在空闲 state 之后返回一个新的 state。

@override
  Stream<VerseState> mapEventToState(
    VerseEvent event,
  ) async* {
if (event is ABCEvent) {
Timer(const Duration(seconds: 3), () {
        print("Here");
        _onTimerEnd(); // adding yield here returns an error.
      })
}

Stream<XYZState> _onTimerEnd() async* {
    print("Yielding a state");
    yield myNewState();
  }

I can see that the code is getting inside the timer callback as I can see the print statements in the callback but not in the timerEnd() method.我可以看到代码正在进入计时器回调,因为我可以在回调中看到打印语句,但在timerEnd()方法中看不到。

State should be yielded by the stream used in bloc that you are current working on. State 应该由您当前正在处理的 bloc 中使用的 stream 产生。 Like喜欢

mapEventToState mapEventToState

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM