add method Null safety
- @override
- ConnectivityEvent event
inherited
Notifies the Bloc
of a new event
which triggers
all corresponding EventHandler
instances.
-
A
StateError
will be thrown if there is no event handler registered for the incomingevent
. -
A
StateError
will be thrown if the bloc is closed and theevent
will not be processed.
Implementation
@override
void add(Event event) {
assert(() {
final handlerExists = _handlers.any((handler) => handler.isType(event));
if (!handlerExists) {
final eventType = event.runtimeType;
throw StateError(
'''add($eventType) was called without a registered event handler.\n'''
'''Make sure to register a handler via on<$eventType>((event, emit) {...})''',
);
}
return true;
}());
try {
onEvent(event);
_eventController.add(event);
} catch (error, stackTrace) {
onError(error, stackTrace);
rethrow;
}
}