如何在一个BLOC中合并多个数据流? [英] How to combine multi data steams in one BLOC?
本文介绍了如何在一个BLOC中合并多个数据流?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个小部件来表示按与用户当前位置最近的位置排序的商店列表,还应该应用过滤.
I have a widget to represent list of stores sorted by nearest to the user current locations also filtering should be applied.
数据输入:
- 存储来自Firestore集合流的数据
- 来自geolacator的当前用户位置.
- 从共享的首选项中过滤选项(可以随时更改)
- 用户选择的列表排序方式
数据输出:经过过滤,排序的商店列表.
Data out: Filtered, sorted, list of stores.
在这种情况下,最佳做法是什么?
What pattern is best practice in this case?
推荐答案
rxdart: https://pub.dartlang.org/packages/rxdart 如果您想将数据合并在一起,可以使用
rxdart : https://pub.dartlang.org/packages/rxdart if you wanna combine data together you can use
var myObservable = Observable.combineLatest3(
myFirstStream,
mySecondStream,
myThirdStream,
(firstData, secondData, thirdData) => print("$firstData $secondData $thirdData"));
you can combine from ( combineLatest2, combineLatest... combineLatest9 )
或CombineLatestStream像这个例子
or CombineLatestStream like this example
CombineLatestStream.list<String>([
Stream.fromIterable(["a"]),
Stream.fromIterable(["b"]),
Stream.fromIterable(["C", "D"])])
.listen(print);
这篇关于如何在一个BLOC中合并多个数据流?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文