Repository navigation
Description
文件选择对话框(IFileOpenDialog)显示延迟 20 秒以上或不显示(Flutter Windows + window_manager 0.7.0 / nativeapi 0.6.1)
IFileOpenDialog shows 20+ seconds late or never appears (Flutter Windows, nativeapi 0.6.1 via window_manager 0.7.0)
中文
环境信息
- Flutter(Dart SDK ^3.13.5),Windows 桌面应用
- Windows 11(build 10.0.26300)
nativeapi: 0.6.1(通过window_manager: 0.7.0引入,也单独显式依赖复现过)window_manager: 0.7.0file_picker: 11.0.3与file_picker: 13.4.0两个版本分别复现
现象
点击按钮调用 FilePicker.pickFiles(...)(应用侧日志确认调用已发起),但原生文件选择对话框窗口(IFileOpenDialog,顶层窗口类 #32770)20 秒以上不出现;一次会话中观察到对话框在点击后约 21 秒才显示。pickFiles 的 Future 一直挂起,直到对话框最终出现并被关闭。
移除 nativeapi / 将 window_manager 回退到 0.5.2 后问题立刻消失(同一份代码、同一台机器、同一测量工具)。
应用启动特征(可能与触发相关)
- 主窗口以隐藏态创建(
CreateWindow不带WS_VISIBLE),Dart 侧在首帧栅格化后才调用 show(防白屏启动设计)。 - 在隐藏窗口态下,
nativeapi.WindowManager.instance.getCurrent()返回null(同时getAll()可枚举到窗口);窗口 show 并获得前台后getCurrent()才可能恢复。
测量方法
自动化基准:模拟鼠标点击"打开文件"按钮 → 以 1ms 粒度轮询本进程可见的 #32770 窗口 → 记录"点击 → 对话框首次可见"耗时;应用侧在 pickFiles 调用前后打 epoch 时间戳与外部时钟对齐。Release 构建(AOT),同一份代码只切换依赖版本。
2×2 数据矩阵(点击 → 对话框可见)
| window_manager | file_picker | 冷启动(进程首次 pickFiles) | 热态(后续调用) |
|---|---|---|---|
| 0.5.2 | 11.0.3 | 1261ms | 704–761ms(7/7 正常触发) |
| 0.5.2 | 13.4.0 | 1354ms | 760–867ms |
| 0.7.0 | 11.0.3 | ❌ pickFiles 已调用,对话框 20s 观察窗口内不出现 | 同左 |
| 0.7.0 | 13.4.0 | ❌ 同样 20s+ 卡死 | 同左 |
关键对照
file_picker 的两个版本在 Windows 上使用完全不同的线程模型:
- 11.x:C++ 原生插件,
IFileOpenDialog跑在 platform 线程(MethodChannel) - 13.x:纯 Dart FFI(
windows_file_picker),对话框跑在compute()的后台 isolate
两种模型在 window_manager 0.5.2 下都正常,在 0.7.0(nativeapi 0.6.1)下都同样被卡 → 卡点不在 file_picker 的调用线程或实现,而在 nativeapi 对主窗口的处理与模态 IFileOpenDialog 显示链路的冲突。
猜测方向(供参考)
- nativeapi_flutter 插件对主窗口的子类化 / 消息处理(或
SetCurrent时序)干扰了对话框 owner 解析或模态消息循环。 - 隐藏窗口态下
getCurrent()为 null 是否导致 nativeapi 内部状态(如 owner 窗口句柄)异常,进而在对话框显示路径上阻塞。
期望
希望定位 nativeapi 0.6.1 中与模态文件对话框冲突的窗口处理逻辑;如有已知的规避方式(例如某个 API 的正确调用时序)也请告知。
English
Environment
- Flutter (Dart SDK ^3.13.5), Windows desktop
- Windows 11 (build 10.0.26300)
nativeapi: 0.6.1(pulled in viawindow_manager: 0.7.0; also reproduced with an explicit direct dependency)window_manager: 0.7.0- Reproduced with both
file_picker: 11.0.3andfile_picker: 13.4.0
Symptom
A button click invokes FilePicker.pickFiles(...) (confirmed by app-side logging), but the native file dialog window (IFileOpenDialog, top-level class #32770) does not appear for 20+ seconds; in one session the dialog only showed up ~21 seconds after the click. The pickFiles future stays pending until the dialog finally appears and gets dismissed.
Removing nativeapi / downgrading window_manager to 0.5.2 makes the problem disappear immediately (same code, same machine, same measurement harness).
App startup characteristics (possibly related)
- The main window is created hidden (
CreateWindowwithoutWS_VISIBLE); Dart-side code calls show only after the first frame is rasterized (anti-white-flash startup design). - In the hidden-window state,
nativeapi.WindowManager.instance.getCurrent()returnsnull(whilegetAll()still enumerates the window);getCurrent()only recovers after the window is shown and focused.
Measurement method
Automated benchmark: simulate a mouse click on the "open file" button → poll for a visible #32770 window of the process at 1ms granularity → record "click → dialog first visible" latency; the app prints epoch timestamps around the pickFiles call, aligned with the harness clock. Release (AOT) builds; only dependency versions differ between runs.
2×2 data matrix (click → dialog visible)
| window_manager | file_picker | Cold (first pickFiles of process) | Warm (subsequent calls) |
|---|---|---|---|
| 0.5.2 | 11.0.3 | 1261ms | 704–761ms (7/7 triggered) |
| 0.5.2 | 13.4.0 | 1354ms | 760–867ms |
| 0.7.0 | 11.0.3 | ❌ pickFiles invoked, dialog never appears within a 20s window | same |
| 0.7.0 | 13.4.0 | ❌ same 20s+ stall | same |
Key observation
The two file_picker versions use completely different threading models on Windows:
- 11.x: C++ native plugin;
IFileOpenDialogruns on the platform thread (MethodChannel) - 13.x: pure Dart FFI (
windows_file_picker); dialog runs in a background isolate viacompute()
Both work fine under window_manager 0.5.2, and both stall under 0.7.0 (nativeapi 0.6.1) → the conflict is not in file_picker's calling thread or implementation, but in nativeapi's handling of the main window conflicting with the modal IFileOpenDialog display path.
Guesses (for reference)
- Subclassing / message handling of the main window by the nativeapi_flutter plugin (or
SetCurrenttiming) interferes with dialog owner resolution or the modal message loop. - Could the
nullresult ofgetCurrent()in hidden-window state leave nativeapi internal state (e.g. owner window handle) inconsistent, blocking the dialog display path?
Ask
Any guidance on which nativeapi 0.6.1 window-handling logic conflicts with modal file dialogs would be greatly appreciated; a known workaround (e.g. correct API call ordering) would also help.
Activity
Merge pull request #41 from libnativeapi/fix/issue-39
Bump screen_retriever to e1635ba (merge PRs #33-#35, #37-#39)