How to replace text in header=ListTile ? #3476
-
Good afternoon
|
Beta Was this translation helpful? Give feedback.
Answered by
burhansvural
Jul 4, 2024
Replies: 2 comments 3 replies
-
from flet import *
def main(page: Page):
page.title = "Test Page"
page.window_width = 430.00
page.window_height = 830.00
expan_text = Text(value="")
subtit_text = Text(value="")
text = ExpansionPanel(
header=ListTile(title=expan_text),
can_tap_header=False
)
# Function to remove panel
def handle_delete(e: ControlEvent):
panel.controls.remove(e.control.data)
page.update()
# The function changes the name of the saved data
def edit(e: ControlEvent):
nonlocal expan_text,subtit_text
# Here you need to add code that will replace the name of the starting text
expan_text.value = f"{edit_text.value}"
subtit_text.value = f"{edit_text.value}"
page.update()
pass
def save_info(e: ControlEvent):
nonlocal expan_text, subtit_text
expan_text.value = f"{start_text.value}"
subtit_text.value = f"{start_text.value}"
text.content = ListTile(
subtitle=subtit_text,
trailing=PopupMenuButton(
icon=icons.MORE_VERT,
items=[
PopupMenuItem('Delete', on_click=handle_delete, data=text),
PopupMenuItem('Change name', on_click=open_dlg_edit, data=text),
]
)
)
panel.controls.append(text)
page.update()
def open_dlg_edit(e):
page.dialog = dlg
dlg.open = True
page.update()
dlg.open = False
# Closes the dialog box after clearing the input field
def close_dlg(e):
edit_text.value = ""
dlg.open = False
page.update()
panel = ExpansionPanelList(
expand_icon_color=colors.AMBER,
elevation=8,
divider_color=colors.AMBER
)
start_text = TextField(label='Start text')
edit_text = TextField(label='New name')
save_b = OutlinedButton('Save', on_click=save_info)
saves = Container(
Column(
controls=[
panel
]
), width=380, height=300, border_radius=15, padding=10
)
dlg = AlertDialog(
title=Text("Change the name?"),
modal=True,
actions=[
Column(
controls=[
edit_text,
Row(
controls=[
TextButton('Cancel', on_click=close_dlg),
TextButton('Save', on_click=edit)
], alignment=MainAxisAlignment.END
)
]
)
]
)
page.add(Column(
controls=[
saves,
start_text,
save_b
]
))
app(target=main) |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you very much, but the program has stopped adding new data) |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@Legolaz7
You can further develop these codes yourself. It has been prepared quickly, just as a simple example.
exp_pnl.py