为了通知目的,我应该在 Rx 流中使用什么类型?
What type should I use in an Rx stream for notifications purpose?
我使用 RxDart
构建了一个 flutter 应用程序,我想创建一个点击事件流。这个流应该包含什么类型? bool
可能对我有用,但我会一直播放 true
。有什么最佳做法吗?
您可以使用 Stream<void>
:
final clickEventStream = PublishSubject<void>();
当你正在收听流时,忽略使用下划线的参数:
clickEventStream.listen((_) { ... })
要将新事件推送到流中,只需添加 null
(这是 void
的有效值):
clickEventStream.add(null);
另见 https://medium.com/dartlang/dart-2-legacy-of-the-void-e7afb5f44df0
我使用 RxDart
构建了一个 flutter 应用程序,我想创建一个点击事件流。这个流应该包含什么类型? bool
可能对我有用,但我会一直播放 true
。有什么最佳做法吗?
您可以使用 Stream<void>
:
final clickEventStream = PublishSubject<void>();
当你正在收听流时,忽略使用下划线的参数:
clickEventStream.listen((_) { ... })
要将新事件推送到流中,只需添加 null
(这是 void
的有效值):
clickEventStream.add(null);
另见 https://medium.com/dartlang/dart-2-legacy-of-the-void-e7afb5f44df0