Flutter 中的 Sink 和 Stream 有什么区别? [英] What is the difference between Sink and Stream in Flutter?
问题描述
关于 Flutter 的
Google I/O 2018 视频解释了如何使用 Dart 流管理 Flutter 应用程序中的状态.演讲者谈到使用Sink
作为输入流和Stream
作为输出流.Sink
和 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屋!