withVoidPointerCallback function

Future<int> withVoidPointerCallback(
  1. dynamic func(
    1. Pointer<NativeFunction<Void Function(Pointer<Void>)>>
    )
)

Implementation

Future<int> withVoidPointerCallback(
    Function(Pointer<NativeFunction<Void Function(Pointer<Void>)>>)
        func) async {
  final completer = Completer<Pointer<Void>>();
  // ignore: prefer_function_declarations_over_variables
  void Function(Pointer<Void>) callback = (Pointer<Void> ptr) {
    completer.complete(ptr);
  };
  final nativeCallable =
      NativeCallable<Void Function(Pointer<Void>)>.listener(callback);
  func.call(nativeCallable.nativeFunction);
  var ptr = await completer.future;
  nativeCallable.close();
  return ptr.address;
}