I have a StreamController
final _controller = StreamController<List<LoadedPage<int, Entity>>>.broadcast();
and stream which exposes data using similar code:
void getPagingData() async {
final response = _api.getData(...);
final pages = _convertResponseToPadingData(response);
// This is an example of exposed event:
// <LoadedPage<int, Entity>>[
// LoadedPage(data: <Entity>[...]),
// LoadedPage(data: <Entity>[...]),
// LoadedPage(data: <Entity>[...]),
// ]
_controller.add(pages);
}
I need to collect all items from data property into the single List<Entity> and expose it as a single event via Stream<List<Entity>>.
Let say I have a list of 3 loaded pages where each page contains finite number of Entity items (for example 30 items). I need to collect all entities from each page to a single List<Entity> (i.e. 90 items) and expose this list to broadcasted stream.
Stream<List<Entity> get entities {
// Here I need an expression which converts Stream<List<LoadedPage<int,Entity>>>
// to Stream<List<Entity>>
}
After many experiments I found the solution:
Result is: