-
-
Save boeledi/2ca3880d69eead1b81ec5f06a2f16518 to your computer and use it in GitHub Desktop.
This file contains 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 ApplicationBloc implements BlocBase { | |
/// | |
/// Synchronous Stream to handle the provision of the movie genres | |
/// | |
final StreamController<List<MovieGenre>?> _syncController = StreamController<List<MovieGenre>?>.broadcast(); | |
Stream<List<MovieGenre>?> get outMovieGenres => _syncController.stream; | |
/// | |
/// Stream to handle a fake command to trigger the provision of the list of MovieGenres via a Stream | |
/// | |
final StreamController<List<MovieGenre>?> _cmdController = StreamController<List<MovieGenre>?>.broadcast(); | |
StreamSink get getMovieGenres => _cmdController.sink; | |
ApplicationBloc() { | |
// | |
// If we receive any data via this sink, we simply provide the list of MovieGenre to the output stream | |
// | |
_cmdController.stream.listen((_){ | |
_syncController.sink.add(UnmodifiableListView<MovieGenre>(_genresList.genres)); | |
}); | |
} | |
void dispose(){ | |
_syncController.close(); | |
_cmdController.close(); | |
} | |
MovieGenresList? _genresList; | |
} | |
// Example of external call | |
BlocProvider.of<ApplicationBloc>(context).getMovieGenres.add(null); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment