Flutter中的Sink和Stream有什么区别? [英] What is the difference between Sink and Stream in Flutter?
问题描述
关于Flutter的Google I / O 2018 视频解释了如何使用Dart流在Flutter应用程序中管理状态。演讲者谈到了将 Sink
用作输入流,以及将 Stream
用作输出流。 接收器
和 Stream
有什么区别?我搜索了文档,但并没有说太多。
The Google I/O 2018 video about Flutter explains how to use Dart streams to manage state in a Flutter application. The speaker talked about using Sink
as input stream and Stream
as output stream. What is the difference between Sink
and Stream
? I searched the documentation but it doesn't say too much thanks.
推荐答案
A StreamSink
是 StreamConsumer
,这意味着它可以接收多个流(由 addStream
)并处理这些流发出的事件。
A StreamSink
is a StreamConsumer
, which means it can take several streams (added by addStream
) and processes the events these streams emit.
如果它是 StreamController
的 StreamSink
,则添加的所有事件流由 StreamController
创建的流发出。
If it is the StreamSink
of a StreamController
then all events from the added streams are emitted by the stream created by the StreamController
.
通过这种方式,您可以通过管道(转发)一个或多个流到另一个。
This way you can pipe (forward) one or more streams into another one.
这篇关于Flutter中的Sink和Stream有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!