addListener method
Registers callback for every WindowEvent this WindowManager emits.
Delivered on the registering isolate, including events from native UI threads. The callback may return a Future; borrowed handles stay valid until it completes. Events queued before removal are skipped if their callback has not started.
Implementation
ListenerId addListener(FutureOr<void> Function(WindowEvent) callback) {
final callable =
ffi.NativeCallable<
ffi.Void Function(
ffi.Pointer<ffi.Void>,
ffi.Uint64,
ffi.Pointer<ffi.Void>,
)
>.listener((
ffi.Pointer<ffi.Void> event,
int delivery,
ffi.Pointer<ffi.Void> _,
) {
unawaited(
NativeCallbacks.deliverEvent(
delivery,
() => event == ffi.nullptr
? null
: WindowEvent.fromNative(
event.cast<c.native_window_event_t>().ref,
),
callback,
),
);
});
return c.native_window_manager_add_listener_async(
callable.nativeFunction.cast(),
NativeCallbacks.userData(callable),
NativeCallbacks.release,
);
}