Skip to content

Instantly share code, notes, and snippets.

@xsahil03x
Last active December 24, 2021 10:26
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 xsahil03x/ed3e325646a71fa7680b88931c3f2a92 to your computer and use it in GitHub Desktop.
Save xsahil03x/ed3e325646a71fa7680b88931c3f2a92 to your computer and use it in GitHub Desktop.
class MovieBloc {
MovieRepository _movieRepository;
StreamController _movieListController;
StreamSink<ApiResponse<List<Movie>>> get movieListSink =>
_movieListController.sink;
Stream<ApiResponse<List<Movie>>> get movieListStream =>
_movieListController.stream;
MovieBloc() {
_movieListController = StreamController<ApiResponse<List<Movie>>>();
_movieRepository = MovieRepository();
fetchMovieList();
}
fetchMovieList() async {
movieListSink.add(ApiResponse.loading('Fetching Popular Movies'));
try {
List<Movie> movies = await _movieRepository.fetchMovieList();
movieListSink.add(ApiResponse.completed(movies));
} catch (e) {
movieListSink.add(ApiResponse.error(e.toString()));
print(e);
}
}
dispose() {
_movieListController?.close();
}
}
@MToheed
Copy link

MToheed commented Dec 23, 2021

Hi Sahil, I'm getting confused from lines 6 to 10. Please explain

@MToheed
Copy link

MToheed commented Dec 24, 2021

https://dart.academy/streams-and-sinks-in-dart-and-flutter/

I got my answers by reading this article. thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment