Unique Chip in row #2614
Answered
by
ndonkoHenri
stephen-lspd
asked this question in
Q&A
-
Right now, Chip supports "on_select" and when adding multiple Chip in a single row you can select all Chip. I know you should use a dropdown or radio or something for this sort of thing but I like the way Chip looks so I was wondering. |
Beta Was this translation helpful? Give feedback.
Answered by
ndonkoHenri
Feb 13, 2024
Replies: 1 comment 1 reply
-
You can do that by looping through all the chips and deselecting all (except the pressed chip). Example below: import flet as ft
def main(page: ft.Page):
page.theme_mode = ft.ThemeMode.LIGHT
def amenity_selected(e):
for i in amenity_chips:
if i != e.control: # if this is not the pressed chip,
i.selected = False # deselect it
page.update()
title = ft.Row([ft.Icon(ft.icons.HOTEL_CLASS), ft.Text("Amenities")])
amenities = ["Washer / Dryer", "Ramp access", "Dogs OK", "Cats OK", "Smoke-free"]
amenity_chips = []
for amenity in amenities:
amenity_chips.append(
ft.Chip(
label=ft.Text(amenity),
bgcolor=ft.colors.GREEN_200,
disabled_color=ft.colors.GREEN_100,
on_select=amenity_selected,
)
)
page.add(title, ft.Row(amenity_chips))
ft.app(target=main) |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
stephen-lspd
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You can do that by looping through all the chips and deselecting all (except the pressed chip). Example below: