Skip to content

Instantly share code, notes, and snippets.

@boeledi
Last active March 27, 2023 08:33
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save boeledi/2ca3880d69eead1b81ec5f06a2f16518 to your computer and use it in GitHub Desktop.
Save boeledi/2ca3880d69eead1b81ec5f06a2f16518 to your computer and use it in GitHub Desktop.
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