Skip to content

Instantly share code, notes, and snippets.

@florent37
Last active December 11, 2018 10:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save florent37/f7722b292b1f3cd4a61b5e4e41f713c3 to your computer and use it in GitHub Desktop.
Save florent37/f7722b292b1f3cd4a61b5e4e41f713c3 to your computer and use it in GitHub Desktop.
class SearchViewModel {
//Stream <=> MediatorLiveData
final StreamController<SearchViewState> _viewModelController = StreamController();
final OmdbRepository _repository;
//Stream <=> LiveData
Stream<SearchViewState> get viewState => _viewModelController.stream;
//constructor
SearchViewModel(this._repository) {
_start();
}
void _start(){
this.search("avengers");
}
void search(String name) async {
var movies = await _repository.searchMovies(name);
_viewModelController.add(SearchViewState(movies: movies));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment