examples
examples copied to clipboard
Chip control has no way of controlling text color when selected
Hello, I found out that Chip
cannot use different label colors for selected and unselected states. Instead, the check mark color can be changed.
Here is an example:
# ...
[
ft.Chip(
label=ft.Text("Chip"),
selected_color=ft.colors.PRIMARY,
check_color=ft.colors.ON_PRIMARY,
on_select=lambda _: page.update(),
)
]
# ...
Result:
It would be nice if there were a way to set also the label to colors.PRIMARY
when selected.
I think an option could be a selected_label_color
-ish argument. Alternatively, the check_color
could be used on label when selected.
I found out that Chip cannot use different label colors for selected and unselected states.
Make the changes in your callback function:
import flet as ft
def main(page: ft.Page):
def chip_callback(e):
x.label_style.color = ft.colors.YELLOW if x.selected else ft.colors.RED
page.update()
x = ft.Chip(
label=ft.Text(
"Chip",
# color=ft.colors.AMBER
),
label_style=ft.TextStyle(weight=ft.FontWeight.BOLD, italic=True, color=ft.colors.RED),
selected_color=ft.colors.PRIMARY,
check_color=ft.colors.ON_PRIMARY,
on_select=chip_callback,
)
page.add(x)
ft.app(target=main)