Skip to content

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Nov 10, 2025

Fix #5119

Example

import flet as ft


def main(page: ft.Page):
    fruits = [
        "Apple",
        "Banana",
        "Cherry",
    ]

    def handle_dropdown_clear(e):
        d1.value = None
        d2.value = None

    options = [ft.DropdownOption(f) for f in fruits]

    page.add(
        d1 := ft.Dropdown(
            label="Dropdown",
            options=options,
        ),
        d2 := ft.DropdownM2(
            label="DropdownM2",
            options=options,
        ),
        ft.Button("Clear", on_click=handle_dropdown_clear),
    )


ft.run(main)

Summary by Sourcery

Fix dropdown text not clearing on value reset, improve state synchronization and refactor item-building logic

Bug Fixes:

  • Ensure dropdown text is cleared when its value is programmatically reset

Enhancements:

  • Track internal value and suppress text-change events when updating the controller
  • Refactor dropdown items construction using collection utilities with null-safe filtering
  • Simplify Dart code style with var declarations and remove obsolete commented code

Documentation:

  • Update Python SDK docstrings for Dropdown and DropdownOption with clearer formatting and examples

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 Dropdown control implementation with better synchronization between the text controller and value changes, along with documentation improvements.

  • Enhanced text controller synchronization to prevent unwanted text change events during programmatic updates
  • Improved null safety handling for dropdown options with explicit validation
  • Updated Flutter API usage from deprecated withOpacity to withValues

Reviewed Changes

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

File Description
sdk/python/packages/flet/src/flet/controls/material/dropdown.py Reformatted docstrings for better clarity and consistency, fixed example to use ft.DropdownOption instead of ft.dropdown.Option
packages/flet/lib/src/controls/dropdown.dart Added state tracking for value changes, implemented text suppression mechanism, improved option validation with null handling, and updated deprecated color API

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

@cloudflare-workers-and-pages
Copy link

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

Deploying flet-docs with  Cloudflare Pages  Cloudflare Pages

Latest commit: 8e6098e
Status: ✅  Deploy successful!
Preview URL: https://2b6ef21b.flet-docs.pages.dev
Branch Preview URL: https://fix-dropdown-clear.flet-docs.pages.dev

View logs

@FeodorFitsner
Copy link
Contributor

Notes:

  1. Remove Example admonition.
  2. Check copilot notes.

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.

Dropdown's value can't be reset/cleared

3 participants