Update streams based on filters in Dart/Flutter

后端 未结 1 430
暖寄归人
暖寄归人 2020-12-10 06:29

I have a BLoC that consumes a raw input Stream (that yields a list of JSON objects) and transforms it to usable objects using a StreamTransformer.

相关标签:
1条回答
  • 2020-12-10 07:15

    Your assumption is correct. You need to create a third steam that takes both your JSON and Filter streams and combine both into a custom result.

    This is usually done with a Stream transformer. Using myStream.transform method. But this is kinda complicated.

    To make things far easier, there's a package called rxdart which basically subclass Stream and adds a few common transformers.

    Using rxdart, you could create this third stream by using combineLatest operator

    Observable<List<String>> list;
    Observable<String> filter;
    
    final output = Observable.combineLatest2(filter, list, (String filter, List<String> list) {
      return list.where((str) => str.startsWith(filter));
    });
    

    More informations on reactivex operators here

    0 讨论(0)
提交回复
热议问题