fromNative static method

ShortcutEvent? fromNative(
  1. native_shortcut_event_t raw
)

Reads the event out of its C form. Returns null for a variant this binding does not know about.

Implementation

static ShortcutEvent? fromNative(c.native_shortcut_event_t raw) {
  if (raw.typeAsInt ==
      c
          .native_shortcut_event_type_t
          .NATIVE_SHORTCUT_EVENT_TYPE_ACTIVATED
          .value) {
    return ShortcutActivatedEvent(
      shortcutId: raw.shortcut_id,
      accelerator: raw.accelerator == ffi.nullptr
          ? null
          : raw.accelerator.cast<pkg_ffi.Utf8>().toDartString(),
    );
  }
  if (raw.typeAsInt ==
      c
          .native_shortcut_event_type_t
          .NATIVE_SHORTCUT_EVENT_TYPE_REGISTERED
          .value) {
    return ShortcutRegisteredEvent(
      shortcutId: raw.shortcut_id,
      accelerator: raw.accelerator == ffi.nullptr
          ? null
          : raw.accelerator.cast<pkg_ffi.Utf8>().toDartString(),
    );
  }
  if (raw.typeAsInt ==
      c
          .native_shortcut_event_type_t
          .NATIVE_SHORTCUT_EVENT_TYPE_UNREGISTERED
          .value) {
    return ShortcutUnregisteredEvent(
      shortcutId: raw.shortcut_id,
      accelerator: raw.accelerator == ffi.nullptr
          ? null
          : raw.accelerator.cast<pkg_ffi.Utf8>().toDartString(),
    );
  }
  if (raw.typeAsInt ==
      c
          .native_shortcut_event_type_t
          .NATIVE_SHORTCUT_EVENT_TYPE_REGISTRATION_FAILED
          .value) {
    return ShortcutRegistrationFailedEvent(
      shortcutId: raw.shortcut_id,
      accelerator: raw.accelerator == ffi.nullptr
          ? null
          : raw.accelerator.cast<pkg_ffi.Utf8>().toDartString(),
      errorMessage: raw.data.registration_failed.error_message == ffi.nullptr
          ? null
          : raw.data.registration_failed.error_message
                .cast<pkg_ffi.Utf8>()
                .toDartString(),
    );
  }
  if (raw.typeAsInt ==
      c
          .native_shortcut_event_type_t
          .NATIVE_SHORTCUT_EVENT_TYPE_RELEASED
          .value) {
    return ShortcutReleasedEvent(
      shortcutId: raw.shortcut_id,
      accelerator: raw.accelerator == ffi.nullptr
          ? null
          : raw.accelerator.cast<pkg_ffi.Utf8>().toDartString(),
    );
  }
  return null;
}