Skip to content

Conversation

@FeodorFitsner
Copy link
Contributor

@FeodorFitsner FeodorFitsner commented Aug 26, 2025

Close #5506

Services can now be used right away, without adding them to page.services, for example:

import flet as ft

async def main(page: ft.Page):

    async def pick_files():
        await ft.FilePicker().pick_files()

    page.add(
        ft.Button("Pick files", on_click=pick_files),
    )


ft.run(main)

Introduces the ServiceHost control in both Dart and Python SDKs, enabling hosting and management of services for child controls. Updates documentation, mkdocs navigation, and core extension registration to support ServiceHost.
Implemented the __call__ method in the Ref class to allow instances to be called directly, returning the current referenced object. This enhances usability and provides a more intuitive API.
Corrected image and anchor links in documentation for tabs and Android publishing. Updated type annotations and return types in cache.py for clarity. Fixed indentation in docstrings for alert_dialog.py and chip.py.
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 introduces a ServiceHost control to both the Dart and Python SDKs, enabling lifecycle management of hosted services. It also includes several API improvements and documentation fixes.

  • ServiceHost control implementation for managing service lifecycles and exposing them to child controls
  • Enhanced Ref control with callable interface for direct value access
  • Improved type annotations and proper service disposal in ServiceRegistry

Reviewed Changes

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

Show a summary per file
File Description
sdk/python/packages/flet/src/flet/controls/ref.py Added __call__ method to Ref for direct value retrieval
sdk/python/packages/flet/src/flet/controls/core/service_host.py New ServiceHost control implementation in Python
sdk/python/packages/flet/src/flet/controls/cache.py Improved typing for cache decorator return signature
sdk/python/packages/flet/src/flet/init.py Added ServiceHost to Python package exports
packages/flet/lib/src/services/service_registry.dart Added dispose method for proper service cleanup
packages/flet/lib/src/controls/service_host.dart New ServiceHost control implementation in Dart
packages/flet/lib/src/flet_core_extension.dart Registered ServiceHost control and reorganized switch cases
sdk/python/packages/flet/mkdocs.yml Added ServiceHost documentation to navigation
sdk/python/packages/flet/docs/controls/servicehost.md Created ServiceHost documentation page
sdk/python/packages/flet/docs/publish/android.md Fixed broken reference link
sdk/python/packages/flet/docs/controls/tabs/index.md Fixed broken image path

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Corrected grammar in the ServiceHost class docstring from 'make' to 'makes' for clarity.
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Aug 26, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 937f0e9
Status: ✅  Deploy successful!
Preview URL: https://270b4eda.flet-docs.pages.dev
Branch Preview URL: https://v1-servicehost.flet-docs.pages.dev

View logs

Replaces 'services' with '_services' in ServiceRegistry and updates related references for encapsulation. Introduces thread safety and cleanup for unreferenced services. Refactors auto-update logic to use a unified 'after_event' method, simplifying event handling and service lifecycle management. Improves error handling in context and updates property access patterns for services in Page.
Updated the Dart PageControl to initialize ServiceRegistry with the main control instead of its child, simplifying service management. In Python, replaced the _page_services ServiceRegistry with a direct _services list, updating references and related tests for consistency.
Deleted the ServiceHost control implementation, its documentation, and references from mkdocs navigation and __init__.py. This change removes ServiceHost from the public API and documentation, likely due to deprecation or refactoring.
Deleted the ServiceHostControl widget and its import and usage from flet_core_extension.dart. This refactor removes support for the ServiceHost control, likely due to deprecation or architectural changes.
@FeodorFitsner FeodorFitsner changed the title v1: ServiceHost control v1: Auto-registering of services Aug 30, 2025
Deleted the unused 'bind' method from the Page class to clean up the codebase and improve maintainability.
Refactored the ServiceRegistry method name from cleanup to unregister_services for clarity. Updated references in session.py to use the new method name.
Deleted the unused ModelT TypeVar declaration to clean up the code in page.py.
@FeodorFitsner FeodorFitsner merged commit e9f126d into main Aug 30, 2025
3 of 4 checks passed
@FeodorFitsner FeodorFitsner deleted the v1-servicehost branch August 30, 2025 14:47
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.

V1: ServiceHost control

2 participants