Flutter Bloc:流的发射器不提供订阅
我正在迁移到 Bloc 8.0.0
进行状态管理。我遇到了一个问题,流的发射器不提供 StreamSubscription
而不是 Future
。我知道,我可以使用 listen
来获取订阅,但我想保持一致性并在任何地方使用 bloc 方式。
使用来自 Emitter
的 forEach
或 onEach
时是否可以获取流订阅?就我而言,我想将流暂停一段时间,然后恢复它,但似乎没有任何方法可以从 emit.forEach
获取订阅。
示例:
await emit.forEach<Model>(
myStream,
onData: (data) => state.copyWith(someData: data.someData),
);
在此示例中,无法获取StreamSubscription
。流自动关闭。我想在这里获取一个订阅对象,这样我就可以暂停流。
也许我错过了一些文档或示例。任何建议都会有很大帮助。
I am migrating to Bloc 8.0.0
for state management. I have run into a problem that an Emitter for a Stream does not provide StreamSubscription
rather a Future
. I know, that I can use listen
to get the subscription but I would like to keep consistency and use bloc way everywhere.
Is it possible to get a stream subscription while using forEach
or onEach
from Emitter
? In my case, I want to pause a stream for some time and then resume it but there does not appear to be any way to get a subscription from emit.forEach<T>{}
.
Example:
await emit.forEach<Model>(
myStream,
onData: (data) => state.copyWith(someData: data.someData),
);
In this example, there is no way to get the StreamSubscription
. Stream is closed automatically. I would like to get a subscription object here, so that, I can pause the stream.
Maybe I missed some documentation or example. Any suggestion would be of great help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论