I am trying to use the bloc pattern to manage data from an API and show them in my widget. I am able to fetch data from API and process it and show it, but I am using a bott
If the error is actually caused by the code you posted, I'd just add a check to ensure no new events are added after dispose()
was called.
class ServiceBloc extends MainBloc {
final _repo = new Repo();
final PublishSubject _serviceController =
new PublishSubject();
Observable 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();