Fix error in bloc after closed causing stack overflow

This commit is contained in:
Ming Ming 2023-05-07 23:12:40 +08:00
parent 067b6a1a60
commit 4762ad02bd

View file

@ -60,7 +60,14 @@ class _Bloc extends Bloc<_Event, _State> {
@override
void onError(Object error, StackTrace stackTrace) {
add(_SetError(error, stackTrace));
// we need this to prevent onError being triggered recursively
if (!isClosed && !_isHandlingError) {
_isHandlingError = true;
try {
add(_SetError(error, stackTrace));
} catch (_) {}
_isHandlingError = false;
}
super.onError(error, stackTrace);
}
@ -144,4 +151,5 @@ class _Bloc extends Bloc<_Event, _State> {
final CollectionsController collectionsController;
StreamSubscription? _collectionControllerSubscription;
var _isHandlingError = false;
}