Repository navigation
Multiselect Dropdown #5525
Unanswered
Xynonners
asked this question in
Extensions
Replies: 2 comments
|
@Xynonners @FeodorFitsner |
0 replies
|
For those still looking for a multiselect in 2026, here's a declarative approach: import dataclasses
from collections.abc import Callable
import flet as ft
@ft.observable
@dataclasses.dataclass
class MultiSelectState:
on_selection_change: Callable[list[str], None]
selected_options: list[str] = dataclasses.field(default_factory=list)
def select_option(self, option: str) -> None:
if option in self.selected_options:
return
self.selected_options.append(option)
self.on_selection_change(self.selected_options)
def unselect_option(self, option: str) -> None:
self.selected_options.remove(option)
self.on_selection_change(self.selected_options)
@ft.component
def MultiSelect(
options: list[str], on_selection_change: Callable[list[str], None]
):
state, _ = ft.use_state(
initial=MultiSelectState(on_selection_change)
)
return ft.Column(
controls=[
ft.AutoComplete(
suggestions=[
ft.AutoCompleteSuggestion(key=option, value=option)
for option in options
],
on_select=lambda e: state.select_option(option=e.control.value)
),
ft.Row(
controls=[
ft.Chip(
label=option,
on_delete=lambda e: state.unselect_option(
option=e.control.label
),
)
for option in state.selected_options
]
)
]
)
|
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment

Uh oh!
There was an error while loading. Please reload this page.
Please Describe The Problem To Be Solved
Multiselect dropdown. Something like the gradio multiselect dropdown or https://pub.dev/packages/multi_select_flutter would be useful to have in flet.
All reactions