fix: honor AppView.FLET_APP_HIDDEN in Windows and Linux desktop runners#6527
fix: honor AppView.FLET_APP_HIDDEN in Windows and Linux desktop runners#6527ihmily wants to merge 2 commits into
Conversation
FeodorFitsner
left a comment
There was a problem hiding this comment.
Thanks — diagnosis is spot on. The Windows runner called Show() on first frame unconditionally, racing past the hidden-on-start logic in packages/flet/lib/src/utils.dart (L19-24). Gating it on FLET_HIDE_WINDOW_ON_START is right, and the [&] → [this, hide_window_on_start] capture is a real fix too (callback fires after OnCreate returns).
One thing: Windows-only. macOS is already covered via window_manager's hiddenWindowAtLaunch(), but Linux still does unconditional gtk_widget_show(window) at linux/my_application.cc:51 — and ixenion in #5897 is on Linux reporting it persists. Extend the guard there too, or track as follow-up?
|
大佬,可否重新编译一个0.28.3的客户端版本,,,,新版本变更太大了,迁移太难了。 |
sure, Then I will compile a package with version 0.28.3 for you |
感谢大佬,,,看到0.85.2中你是国内的贡献者的时候,我就知道窗口居中闪烁的问题有救了。。。哈哈。 |
|
Good catch — I extended the fix to Linux as well. gtk_widget_show(GTK_WIDGET(window));That meant the GTK window was mapped before Dart/window_manager had a chance to apply the hidden-on-start behavior, so gtk_widget_realize(GTK_WIDGET(window));So the native window is created/realized, but not shown yet. That keeps the actual show/hide decision in Dart, where Linux native runner: New Files modified: TestRefer to @ixenion in # 5897
I also test it by Ubuntu 24.04 running in WSL2 (host is windows 10). The test results are consistent with what @ixenion mentioned. For example Launching with the hidden window mode doesn't work properly. Additionally, the window centering is intermittent and does not match our expected behavior. As shown below Before_2026_05_29_14_44_13_763.mp4Fixed_2026_05_29_14_46_14_379.mp4Kindly review and merge it promptly. |
Download fix/window-hide-start-for-windows:flet_desktop_package-v0.28.3 After extracting the archive, replace the folder Lib\site-packages\flet_desktop\app\flet with the flet folder from the extracted files. |
Thanks so much |
There was a problem hiding this comment.
Pull request overview
Fixes the Windows desktop runner so ft.run(..., view=AppView.FLET_APP_HIDDEN) (which sets FLET_HIDE_WINDOW_ON_START=true) actually keeps the native window hidden during startup, eliminating the brief top-left flash before Dart-side positioning happens. The Linux runner is changed to realize the window without showing it so Dart can control the show timing, and WindowService defers alignment/center calls on Linux until after the first show event. The window event handler is also refactored to avoid querying getWindowState() during close/hide/post-destroy transitions, where the call can hang or race.
Changes:
- Add
HasEnvironmentVariablehelper in Windows runnerutils.{h,cpp}(both client and template) and use it inFlutterWindow::OnCreateto skip the first-frameShow()whenFLET_HIDE_WINDOW_ON_STARTis set. - Replace
gtk_widget_show(window)withgtk_widget_realize(window)in the Linux client runner, matching the existing template behavior. - Refactor
WindowService: cache helpers_cacheWindowState/_snapshotWindowState, Linux-only deferred alignment/center until theshowevent, and special-cased event handling forclose/hide/closing state to avoid awaitinggetWindowState().
Reviewed changes
Copilot reviewed 8 out of 8 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| client/windows/runner/utils.h | Declares HasEnvironmentVariable helper. |
| client/windows/runner/utils.cpp | Implements HasEnvironmentVariable via GetEnvironmentVariableW + GetLastError. |
| client/windows/runner/flutter_window.cpp | Skip Show() on first frame when FLET_HIDE_WINDOW_ON_START is present. |
| sdk/python/templates/build/.../windows/runner/utils.h | Template mirror of new helper declaration. |
| sdk/python/templates/build/.../windows/runner/utils.cpp | Template mirror of helper implementation. |
| sdk/python/templates/build/.../windows/runner/flutter_window.cpp | Template mirror of conditional Show(). |
| client/linux/my_application.cc | Realize window instead of showing it, letting Dart control visibility. |
| packages/flet/lib/src/services/window.dart | Defer Linux alignment/center until show; refactor event handling to avoid getWindowState() during close/hide. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Description
This PR fixes a Windows desktop startup issue where
ft.run(..., view=ft.AppView.FLET_APP_HIDDEN)does not keep the native app window fully hidden during startup.Although the Python and Dart layers already support hidden startup mode via
FLET_HIDE_WINDOW_ON_START, the Windows native runner still calledShow()unconditionally on the first Flutter frame. As a result,flet.execould briefly flash in the top-left corner before the app finished operations such as resizing or centering the window.This change updates the Windows desktop runner to respect
FLET_HIDE_WINDOW_ON_STARTbefore showing the native window.The same fix is also applied to the Windows app template runner so generated apps behave consistently.
Fixes #5914 、#5897
Test code
Type of change
Checklist
website/sidebars.ymlfor breaking changes, removals, and deprecations, if applicable.Screenshots
Before:
On Windows, flet.exe briefly flashes in the top-left corner during startup.
After:
With AppView.FLET_APP_HIDDEN, the window remains hidden until page.window.visible = True.
_2026_05_27_15_39_27_670.mp4
Summary by Sourcery
Respect hidden-startup configuration when showing Windows desktop windows.
Bug Fixes:
Enhancements: