Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Resizing a ListView with ExpansionTiles #4630

Open
1 task done
HerrWaffel opened this issue Dec 27, 2024 Discussed in #4531 · 0 comments
Open
1 task done

Resizing a ListView with ExpansionTiles #4630

HerrWaffel opened this issue Dec 27, 2024 Discussed in #4531 · 0 comments

Comments

@HerrWaffel
Copy link

Discussed in #4531

Originally posted by HerrWaffel December 9, 2024

Question

Hey,
I ran into some weird behaviour when trying to adjust the height of a ListView which contains ExpansionTiles.

When the ExpansionTile is changed and tries to adjust the height or expand property of the ListView parent, the ListView updates but cancels the opening of the ExpansionTile. After clicking the tile again, it opens correctly.
It does this when changing the height, expand or both on the ListView.

Is this a bug, or am I setting up something weird?

The behaviour I want is to limit the height of the ListView when any of the ExpansionTiles are expanded; otherwise, it needs to expand.

Thanks,

Code sample

import flet as ft
from time import sleep

class Example(ft.Column):
    def __init__(self):

        self.tile_list = ft.ListView(
            controls=[
                ft.ExpansionTile(
                    title=ft.Text("First Tile"),
                    controls=[
                        ft.Text("First Tile Content")
                    ],
                    on_change=self.on_expansion_change,
                    data="false",
                ),
                ft.ExpansionTile(
                    title=ft.Text("Second Tile"),
                    controls=[
                        ft.Text("Second Tile Content")
                    ],
                    on_change=self.on_expansion_change,
                    data="false",
                ), 
            ],
            expand=True,
            spacing=2,
        )

        self.delay_switch = ft.Switch(
            label=" Enable Delay",
        )

        self.layout = [
            self.tile_list,
            ft.Text("End of ListView", expand=True),
            self.delay_switch,   
        ]
        
        super().__init__(
            controls=self.layout,
            expand=True,
        )

    def on_expansion_change(self, e):
        e.control.data = e.data
        if self.delay_switch.value:
            sleep(1)
        self.update_tile_list()

    def update_tile_list(self):
        has_expanded_tile = False
        for tile in self.tile_list.controls:
            if tile.data == "true":
                has_expanded_tile = True
                break
        
        self.tile_list.expand = not has_expanded_tile
        self.tile_list.height = 200 if has_expanded_tile else None

        self.update()
        
def main(page: ft.Page):
    page.add(Example())


ft.app(main)

Error message

No response

------------------------------------------------------

  • I have searched for answers to my question both in the issues and in previous discussions.
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

No branches or pull requests

1 participant