createWithIdAndAcceleratorAndCallback static method

Shortcut? createWithIdAndAcceleratorAndCallback(
  1. ShortcutId id,
  2. String accelerator,
  3. void callback()
)

Creates a new Shortcut; returns null if the native side failed.

Implementation

static Shortcut? createWithIdAndAcceleratorAndCallback(
  ShortcutId id,
  String accelerator,
  void Function() callback,
) {
  final acceleratorNative = accelerator.toNativeUtf8().cast<ffi.Char>();
  final callbackCallable =
      ffi.NativeCallable<
        ffi.Void Function(ffi.Pointer<ffi.Void>)
      >.isolateLocal((ffi.Pointer<ffi.Void> _) {
        callback();
      });
  final handle = c
      .native_shortcut_create_with_id_and_accelerator_and_callback(
        id,
        acceleratorNative,
        callbackCallable.nativeFunction,
        NativeCallbacks.userData(callbackCallable),
        NativeCallbacks.release,
      );
  pkg_ffi.calloc.free(acceleratorNative);
  if (handle == 0) return null;
  return Shortcut.fromHandle(handle);
}