Skip to content

Conversation

@ndonkoHenri
Copy link
Contributor

@ndonkoHenri ndonkoHenri commented Dec 1, 2023

Close #1718

Test Code:

import flet as ft


def main(page: ft.Page):
    page.theme_mode = ft.ThemeMode.LIGHT

    def handle_change(e: ft.ControlEvent):
        index = int(e.data)
        panel.controls[index].is_expanded = not panel.controls[index].is_expanded
        page.update()

    def handle_delete(e: ft.ControlEvent):
        panel.controls.remove(e.control.data)
        page.update()

    panel = ft.ExpansionPanelList(
        expand_icon_color=ft.colors.AMBER,
        elevation=8,
        divider_color=ft.colors.AMBER,
        on_change=handle_change,
        controls=[
            ft.ExpansionPanel(
                bgcolor=ft.colors.BLUE_400,
                is_expanded=True,
            ),
        ],
    )

    colors = [
        ft.colors.GREEN_500,
        ft.colors.BLUE_800,
        ft.colors.RED_800,
    ]
    
    for i in range(3):
        exp = ft.ExpansionPanel(
            bgcolor=colors[i % len(colors)],
            header=ft.ListTile(title=ft.Text(f"Panel {i}")),
        )

        exp.content = ft.ListTile(
            title=ft.Text(f"This is in Panel {i}"),
            subtitle=ft.Text(f"Press the icon to delete panel {i}"),
            trailing=ft.IconButton(ft.icons.DELETE, on_click=handle_delete, data=exp),
        )

        panel.controls.append(exp)

    page.add(panel)


ft.app(target=main)

@FeodorFitsner FeodorFitsner merged commit f921a6d into main Dec 4, 2023
@ndonkoHenri ndonkoHenri deleted the expansion-panel branch December 4, 2023 19:49
zrr1999 pushed a commit to zrr1999/flet that referenced this pull request Jul 17, 2024
* initial commit

* simplify ExpansionTile `on_change`

* Expand/collapse ExpansionPanels on a Dart side

* `is_expanded` -> `expand`

---------

Co-authored-by: Feodor Fitsner <feodor@appveyor.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ExpansionPanelList control

2 participants