event method
AppEventHandle
event(
- String name, {
- required AppEventScope scope,
- StructHandle? dataStruct,
- ActionBlockTarget? handler,
- String description = '',
Declares a reusable app event.
Global events may optionally bind an app-level action block as their
global handler. Local events must attach handlers later via
AddLocalEventHandler(...).
Implementation
AppEventHandle event(
String name, {
required AppEventScope scope,
StructHandle? dataStruct,
ActionBlockTarget? handler,
String description = '',
}) {
_ensureUnique(_appEventNames, name, 'app event');
if (scope == AppEventScope.local && handler != null) {
throw StateError(
'Local events cannot declare handler:. Use AddLocalEventHandler(...) instead.',
);
}
final declaration = AppEventDeclaration(
name: name,
key: generateRandomAlphaNumericString(),
scope: scope,
dataStruct: dataStruct,
handler: handler,
description: description,
);
_appEvents.add(declaration);
return AppEventHandle(
name: name,
key: declaration.key,
scope: scope,
dataStruct: dataStruct,
);
}