Want to add new events after calling close in flutter? I had just add a check to ensure no new events are added after dispose() was called.
Here is an example:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
class ServiceBloc extends MainBloc { final _repo = new Repo(); final PublishSubject<ServiceModel> _serviceController = new PublishSubject<ServiceModel>(); Observable<ServiceModel> get allServices => _serviceController.stream; getAllServices() async { // do nothing if already disposed if(_isDisposed) { return; } appIsLoading(); ServiceModel movieItem = await _repo.getAllServices(); _serviceController.sink.add(movieItem); appIsNotLoading(); } bool _isDisposed = false; void dispose() { _serviceController.close(); _isDisposed = true; } } ServiceBloc serviceBloc = new ServiceBloc(); |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.