Skip to content

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Nov 20, 2025

Fix #2705

Summary by Sourcery

Refactor desktop window handling by replacing the WindowControl widget with a dedicated WindowService, fix hidden window startup behavior, and streamline service bindings in PageControl. Update Python SDK integration tests for improved stability and add new examples for hidden and resized windows.

New Features:

  • Introduce WindowService to handle desktop window operations instead of a StatefulWidget control
  • Add Python examples for starting with a hidden window and programmatically resizing windows

Bug Fixes:

Enhancements:

  • Refactor window logic into a dedicated Flutter service with improved initialization, listener management, and platform checks
  • Consolidate service registry initialization in PageControl to manage page, user, and window services
  • Remove embedded WindowControl from view overlays and update core extension to bind WindowService

Documentation:

  • Add example demonstrating launching an app with a hidden window and showing it later
  • Include a window resize example in Python examples

Tests:

  • Update Python SDK integration tests for TimePicker, ShaderMask, CupertinoActionSheet, and ContextMenu to use consistent page.update and pump sequences

Moved window logic from controls/window.dart to services/window.dart, converting WindowControl to WindowService and updating its integration. Updated page and core extension to use the new service, removed window overlay from view, and adjusted backend and related code to support the refactor. This change improves separation of concerns by treating window management as a service rather than a UI control.
Added comments explaining how to run the example with the --hidden option using `flet run`. Also added a print statement to notify that the window is hidden on start and will show after 3 seconds.
Refactored material time picker integration tests for improved clarity and consistency, updating dialog creation and page update order. Added a new example for window resizing in desktop apps. Updated golden image and other related test files.
Added explicit page update and await pump_and_settle before opening the time picker in test_basic. This ensures the page is fully rendered and stable before interaction, reducing test flakiness.
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We've reviewed this pull request using the Sourcery rules engine

Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR refactors desktop window handling in Flet by converting the WindowControl widget to a WindowService, addressing issue #2705 where windows hidden at startup would not become visible when toggled.

Key changes:

  • Refactored WindowControl from a StatefulWidget to a FletService for better lifecycle management
  • Fixed hidden window retrieval by using visibleOnly: false parameter in backend communication
  • Updated Python SDK integration tests to use consistent page.update() and pump_and_settle() sequences

Reviewed Changes

Copilot reviewed 12 out of 13 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
packages/flet/lib/src/services/window.dart Refactored from StatefulWidget to FletService with improved initialization and platform checks
packages/flet/lib/src/controls/page.dart Added service registry management for window, page, and user services with proper lifecycle handling
packages/flet/lib/src/flet_backend.dart Added visibleOnly: false parameter for hidden window retrieval and rethrow for connection errors
packages/flet/lib/src/flet_core_extension.dart Moved Window from widget factory to service factory
packages/flet/lib/src/controls/view.dart Removed embedded WindowControl widget from view overlays
sdk/python/examples/controls/page/window_hidden_on_start.py New example demonstrating hidden window startup with visibility toggle
sdk/python/examples/controls/page/window_resize.py New example showing programmatic window resizing
sdk/python/packages/flet/integration_tests/examples/material/test_time_picker.py Updated test to call page.update() before showing dialog for stability
sdk/python/packages/flet/integration_tests/examples/material/test_context_menu.py Added pump_and_settle() after page update for consistency
sdk/python/packages/flet/integration_tests/examples/cupertino/test_cupertino_action_sheet.py Reordered operations to update page before adding dialog
sdk/python/packages/flet/integration_tests/examples/core/test_shader_mask.py Refactored to separate image creation, update page, then add shader mask
sdk/python/packages/flet/integration_tests/controls/material/test_time_picker.py Updated tests with consistent update and pump patterns
sdk/python/packages/flet/integration_tests/examples/material/golden/macos/context_menu/programmatic_open.png Updated golden test image
Comments suppressed due to low confidence (1)

packages/flet/lib/src/services/window.dart:99

  • If an error occurs during window state initialization (line 97-99), the _initWindowStateCompleter is never completed. This could cause _scheduleWindowUpdate() to hang indefinitely waiting for the completer to finish (line 114-115). Consider completing the completer with an error in the catch block: _initWindowStateCompleter.completeError(e); or complete it normally to allow the app to continue.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Eliminated the rethrow statement in the FletBackend connection error handler to prevent exceptions from propagating and to handle errors more gracefully.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Nov 20, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 7c4528c
Status: ✅  Deploy successful!
Preview URL: https://eb21be13.flet-docs.pages.dev
Branch Preview URL: https://start-hidden-window-fix.flet-docs.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Window visibility not working as expected with FLET_APP_HIDDEN

2 participants