Skip to content

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Oct 21, 2025

Fix #2874

Example code

import flet as ft

colors = [
    "Amber",
    "Blue Grey",
    "Brown",
    "Deep Orange",
    "Green",
    "Light Blue",
    "Light Green",
    "Orange",
    "Red",
]


def main(page: ft.Page):
    page.horizontal_alignment = ft.CrossAxisAlignment.CENTER

    def build_tiles(items: list[str]) -> list[ft.ListTile]:
        return [
            ft.ListTile(
                title=ft.Text(item),
                data=item,
                on_click=handle_tile_click,
            )
            for item in items
        ]

    async def handle_tile_click(e: ft.Event[ft.ListTile]):
        await anchor.close_view()

    async def handle_change(e: ft.Event[ft.SearchBar]):
        query = e.control.value.strip().lower()
        matching = (
            [color for color in colors if query in color.lower()] if query else colors
        )
        anchor.controls = build_tiles(matching)

    def handle_submit(e: ft.Event[ft.SearchBar]):
        print(f"Submit: {e.data}")

    async def handle_tap(e: ft.Event[ft.SearchBar]):
        await anchor.open_view()

    page.add(
        anchor := ft.SearchBar(
            view_elevation=4,
            divider_color=ft.Colors.AMBER,
            bar_hint_text="Search colors...",
            view_hint_text="Choose a color from the suggestions...",
            on_change=handle_change,
            on_submit=handle_submit,
            on_tap=handle_tap,
            controls=build_tiles(colors),
        ),
    )


ft.run(main)

Summary by Sourcery

Introduce platform accessibility feature retrieval to SemanticsService and enhance SearchBar suggestion handling, complemented by updated documentation and examples.

New Features:

  • Add SemanticsService.get_accessibility_features() to retrieve platform accessibility flags as an AccessibilityFeatures object
  • Implement dynamic rendering of SearchBar suggestions via a dedicated suggestions host widget

Enhancements:

  • Define AccessibilityFeatures dataclass in Python and map platform features in Dart
  • Streamline SearchBar control by removing blur handling and debug prints
  • Add argument handling and docstrings for SemanticsService announce methods

Documentation:

  • Extend publishing guide with flet build metadata options for product, company, and copyright
  • Update SearchBar control and SemanticsService documentation with clarified property descriptions and usage examples
  • Refresh Python examples for SearchBar and SemanticsService accessibility feature retrieval

@ndonkoHenri ndonkoHenri requested a review from Copilot October 21, 2025 23:59
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 improves the SearchBar control's handling of dynamic suggestion lists and adds a new method to retrieve accessibility features from the platform. The key changes include refactoring the SearchBar's suggestions rendering mechanism and extending the SemanticsService API.

  • Refactored SearchBar suggestions to use a stateful widget that properly responds to control updates
  • Added SemanticsService.get_accessibility_features() method to query platform accessibility settings
  • Enhanced documentation across multiple controls and updated examples

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
sdk/python/packages/flet/src/flet/controls/services/semantics_service.py Added AccessibilityFeatures dataclass and get_accessibility_features() method with comprehensive documentation
sdk/python/packages/flet/src/flet/controls/material/search_bar.py Improved documentation formatting, clarified event handler descriptions, and removed unused blur() method
sdk/python/packages/flet/docs/publish/index.md Reorganized documentation sections, moving build configuration topics and adding product metadata sections
sdk/python/packages/flet/docs/controls/semanticsservice.md Enhanced documentation structure with examples and proper member listings
sdk/python/examples/controls/semantics_service/accessibility_features.py Added new example demonstrating accessibility features retrieval
sdk/python/examples/controls/search_bar/basic.py Updated to demonstrate dynamic filtering of SearchBar suggestions
packages/flet/lib/src/services/semantics_service.dart Implemented get_accessibility_features method and improved message variable scoping
packages/flet/lib/src/controls/search_bar.dart Introduced _SearchBarSuggestionsHost stateful widget for proper suggestion list updates and removed unused blur method

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

@ndonkoHenri ndonkoHenri changed the title Improve handling of SearchBar suggestions + SemanticsService.get_accessibility_features Improve handling of SearchBar suggestions + SemanticsService.get_accessibility_features Oct 22, 2025
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@cloudflare-workers-and-pages
Copy link

cloudflare-workers-and-pages bot commented Oct 22, 2025

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: ed241dd
Status: ✅  Deploy successful!
Preview URL: https://25449de8.flet-docs.pages.dev
Branch Preview URL: https://fix-searchbar-updates.flet-docs.pages.dev

View logs

@FeodorFitsner FeodorFitsner merged commit cb71135 into main Oct 24, 2025
25 of 46 checks passed
@FeodorFitsner FeodorFitsner deleted the fix-searchbar-updates branch October 24, 2025 16:00
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.

Updating SearchBar.controls doesn't trigger it's rebuild

3 participants