supportsEventOf method
Returns true if the listener supports the given event.
This method is used by the event publisher to determine if the listener
should be notified of the event. The default implementation checks if
the event is an instance of the generic type E
.
Override this method to provide custom event filtering logic when
the listener should only handle specific instances of event type E
.
Parameters:
event
: The event to check for support
Returns:
true
if this listener can handle the given event, false
otherwise
Default Behavior:
The default implementation returns event is E
, meaning the listener
will receive all events that are instances of type E
or its subtypes.
Custom Filtering Example:
class SpecificUserEventListener implements ApplicationEventListener<UserEvent> {
final String targetUsername;
SpecificUserEventListener(this.targetUsername);
@override
bool supportsEventOf(ApplicationEvent event) {
return event is UserEvent && event.user.username == targetUsername;
}
@override
void onApplicationEvent(UserEvent event) {
// Only called for events matching the target username
print('Target user action: ${event.action}');
}
}
Performance Considerations:
This method is called for every event dispatch, so keep the logic efficient. For complex filtering, consider using multiple specialized listener implementations instead.
See also:
- onApplicationEvent for the actual event handling
GenericApplicationEventMulticaster
for the dispatch implementation
Implementation
@override
bool supportsEventOf(ApplicationEvent event) => event is ApplicationContextEvent;