Last active
December 24, 2021 10:26
-
-
Save xsahil03x/ed3e325646a71fa7680b88931c3f2a92 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | |
} | |
} |
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
Hi Sahil, I'm getting confused from lines 6 to 10. Please explain