event method

AppEventHandle event(
  1. String name, {
  2. required AppEventScope scope,
  3. StructHandle? dataStruct,
  4. ActionBlockTarget? handler,
  5. 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 = '',
}) {
  _ensureNotPendingRemoval(
    _pendingRemovals,
    name,
    'app event',
    'removeAppEvent',
  );
  _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,
  );
}