pickSingleFileAsync method

Future<StorageFile?> pickSingleFileAsync()

Implementation

Future<StorageFile?> pickSingleFileAsync() {
  final retValuePtr = calloc<COMObject>();
  final completer = Completer<StorageFile?>();

  final hr = ptr.ref.vtable
          .elementAt(15)
          .cast<
              Pointer<
                  NativeFunction<
                      HRESULT Function(Pointer, Pointer<COMObject>)>>>()
          .value
          .asFunction<int Function(Pointer, Pointer<COMObject>)>()(
      ptr.ref.lpVtbl, retValuePtr);

  if (FAILED(hr)) {
    free(retValuePtr);
    throw WindowsException(hr);
  }

  final asyncOperation = IAsyncOperation<StorageFile?>.fromRawPointer(
      retValuePtr,
      creator: StorageFile.fromRawPointer);
  completeAsyncOperation(
      asyncOperation, completer, asyncOperation.getResults);

  return completer.future;
}