initialize static method

void initialize(
  1. IInspectable target, [
  2. int? hwnd
])

Specifies an owner window to be used by a Windows Runtime object that is used in a desktop app.

target must be a WinRT object that implements the IInitializeWithWindow interface (e.g. FileOpenPicker).

hwnd represents the handle of the window to be used as the owner window. Use GetConsoleWindow() for console apps or GetShellWindow() for Flutter apps. By default, GetShellWindow() is used.

final picker = FileOpenPicker()
  ..suggestedStartLocation = PickerLocationId.desktop
  ..viewMode = PickerViewMode.thumbnail;
final filters = picker.fileTypeFilter..append('*'); // Allow all types
InitializeWithWindow.initialize(picker);
final pickedFile = await picker.pickSingleFileAsync();

Implementation

static void initialize(IInspectable target, [int? hwnd]) {
  hwnd ??= GetShellWindow();

  final initializeWithWindow = IInitializeWithWindow.from(target);
  try {
    final hr = initializeWithWindow.initialize(hwnd);
    if (FAILED(hr)) throw WindowsException(hr);
  } finally {
    initializeWithWindow.release();
  }
}