Can not set the value of the dropdown. I'm using an example from the flet site.
The only way of set the value is add some item do the dropdown but
But what i need is set the value without any selection item?
Thank you!
import flet as ft
def main(page: ft.Page):
def find_option(option_name):
for option in d.options:
if option_name == option.key:
return option
return None
def add_clicked(e):
d.value = "test"
page.update()
def delete_clicked(e):
option = find_option(d.value)
if option != None:
d.options.remove(option)
# d.value = None
page.update()
d = ft.Dropdown()
option_textbox = ft.TextField(hint_text="Enter item name")
add = ft.ElevatedButton("Add", on_click=add_clicked)
delete = ft.OutlinedButton("Delete selected", on_click=delete_clicked)
page.padding = 50
page.add(d, ft.Row(controls=[option_textbox, add, delete]))
ft.app(target=main)
flet.Dropdown need flet.dropdown.Option in the 'options' list with the same value you want set.
the example is here: