我有一个Observable,它用作StreamView封装的ListView的源。此Observable取决于某些类别选择器:
final _categorySubject = BehaviourSubject<int>(); // category id
final _searchSubject = PublishSubject<String>(); // search term
Observable<SearchState> get items => _categorySubject
.switchMap((catId) => Observable(_getItems())) // catId is taken from _categorySubject.value
...
StreamBuilder(
stream: bloc.items
...
)
但是我还需要使用_searchSubject在结果项中进行搜索。
Observable<SearchState> get items2 => _searchSubject
.switchMap((searchTerm) => Observable(_getItems(searchTerm)))
我需要一些想法,如何将两个可观察对象结合在一起用于单个StreamBuilder?启用搜索模式(可见搜索字段)时如何将搜索结果作为源流“注入”,并在禁用搜索时如何切换到原始items
属性?