Luis Cardoza Bird
Luis Cardoza Bird

Reputation: 1472

Flutter merge two Stream<List<Data>> into a single Stream<List<Data>>

There's an issue that i hasn't been able to solve, currently i have a

  Stream<List<SupplyHierarchy>> get suppliesHierarchyFinalLevel => _supplyHierarchyFinalLevelFetcher.stream;
  Stream<List<SupplyHierarchy>> get suppliesHierarchyLevelFour => _supplyHierarchyLevelFourFetcher.stream;

  final _supplyHierarchyLevelFourFetcher = PublishSubject<List<SupplyHierarchy>>();
  final _supplyHierarchyFinalLevelFetcher = PublishSubject<List<SupplyHierarchy>>();

Stream<List<SupplyHierarchy>> getData() {
    return StreamGroup.merge(
        [suppliesHierarchyFinalLevel, suppliesHierarchyLevelFour]);  
}

the output that i receive is a List but with only one of the streams. it do something like this:

StreamGroup.merge([LIST_WITH_DATA, NULL]);  

Even when both streams have data loaded.

Any one call guide me about how to solve this issue... thanks.

Upvotes: 1

Views: 1338

Answers (1)

David Schneider
David Schneider

Reputation: 609

import 'package:async/async.dart'; // using v2.5.0

void main() {
  final s1= Stream.periodic(Duration(seconds:1), (count) => count);
  final s2= Stream.periodic(Duration(seconds:2), (count) => 100-count);
  StreamGroup.merge([s1, s2]).listen(print);
}

works fine for me, could you provide a minimal code snippet that allows reproducing the error? Your "example" uses a lot of variables not shown, probably that's where you have an error.

Please do not post your entire source code as people sometimes tend to do when asked for a "minimal example".

Upvotes: 2

Related Questions