remoteController<C extends StateController> method
This function returns Controller
instance as a Steam based on the type
you attached with the function.
Example
This example returns todo list filtered by searchCategory.
We need SearchCategoryController
stream combining with TodoContrroller's
stream:
Stream<List<Todo>> get todo$ =>
Rx.combineLates2<List<Todo>, SearchCategory, List<Todo>>(
stream$, remoteCubit<SearchCategoryController>()
.flatMap((event) => event.stream$),(todos, category) {
switch (category) {
case SearchCategory.Active:
return todos.where((todo) => !todo.completed).toList();
case SearchCategory.Completed:
return todos.where((todo) => todo.completed).toList();
default:
return todos;
}
});
Implementation
Stream<C> remoteController<C extends StateController>() =>
Stream.fromFuture(_remoteData<C>());