flet icon indicating copy to clipboard operation
flet copied to clipboard

ListView and GridView within a ExpansionTile are not scrollable

Open gcilli opened this issue 1 year ago • 4 comments

Duplicate Check

  • [x] I have searched the opened issues and there are no duplicates

Describe the bug

Hello, I noticed that when a ListView or a GridView is placed within the list of controls of an ExpansionTIle, they are not scrollable. Their content simply extend over the screen size.

Code sample

Code
import flet as ft


def main(page: ft.Page):
    page.title = "Scrollable ExpansionTile Example"

    # Create a ListView to hold the content of the ExpansionTile
    list_view = ft.ListView(
        expand=1,  # Allow the ListView to expand and fill available space
        spacing=10,  # Space between items
        padding=20,  # Padding around the ListView
        auto_scroll=True  # Automatically scroll to the end when new items are added
    )

    # Add multiple items to the ListView
    for i in range(1, 101):  # Example: 100 items
        list_view.controls.append(ft.Text(f"Item {i}"))

    # Create an ExpansionTile and add the ListView as its content
    expansion_tile = ft.ExpansionTile(
        title=ft.Text("Expandable Section"),
        controls=[list_view],
        expand=True
    )

    # Add the ExpansionTile to the page
    page.add(expansion_tile)


# Run the Flet app
ft.app(main)

To reproduce

  1. Run the code above: flet run --web
  2. Click on the arrow on the right in order to expand the tile
  3. Try to scroll the list

Expected behavior

I expect the ListView to be scrollable.

Screenshots / Videos

Captures

Image

Operating System

Linux

Operating system details

Ubuntu 20.04

Flet version

0.24.0

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
[Paste your logs here]

Additional details

No response

gcilli avatar Mar 20 '25 16:03 gcilli

It happens because the ListView attempts to expand infinitely (have unbounded height constraints).

Here are some suggestions:

  • give the ListView a fixed height:

    Details

    import flet as ft
    
    
    def main(page: ft.Page):
        page.add(
            ft.ExpansionTile(
                title=ft.Text("Expandable Section"),
                controls=[
                    ft.ListView(
                        height=300,
                        spacing=10,
                        padding=20,
                        auto_scroll=True,
                        controls=[ft.Text(f"Item {i}") for i in range(1, 101)],
                    ),
                ],
            )
        )
    
    ft.app(main)
    

  • set page.scroll - LV props like auto_scroll won't have a visible effect here though:

    Details

    import flet as ft
    
    
    def main(page: ft.Page):
        page.scroll = True
    
        page.add(
            ft.ExpansionTile(
                title=ft.Text("Expandable Section"),
                controls=[
                    ft.ListView(
                        spacing=10,
                        padding=20,
                        auto_scroll=True,
                        controls=[ft.Text(f"Item {i}") for i in range(1, 101)],
                    ),
                ],
            )
        )
    
    ft.app(main)
    

ndonkoHenri avatar Mar 23 '25 01:03 ndonkoHenri

However in case of using a Container it works:

import flet as ft


def main(page: ft.Page):
   page.add(
       ft.Container(
           content=
               ft.ListView(
                   spacing=10,
                   padding=20,
                   auto_scroll=True,
                   controls=[ft.Text(f"Item {i}") for i in range(1, 101)],
               ),
               expand=True,
       )
   )

ft.app(main)

Alexukg avatar Mar 23 '25 21:03 Alexukg

It happens because the ListView attempts to expand infinitely (have unbounded height constraints).

Here are some suggestions:

  • give the ListView a fixed height: Details

    import flet as ft

    def main(page: ft.Page): page.add( ft.ExpansionTile( title=ft.Text("Expandable Section"), controls=[ ft.ListView( height=300, spacing=10, padding=20, auto_scroll=True, controls=[ft.Text(f"Item {i}") for i in range(1, 101)], ), ], ) )

    ft.app(main)

  • set page.scroll - LV props like auto_scroll won't have a visible effect here though: Details

    import flet as ft

    def main(page: ft.Page): page.scroll = True

    page.add(
        ft.ExpansionTile(
            title=ft.Text("Expandable Section"),
            controls=[
                ft.ListView(
                    spacing=10,
                    padding=20,
                    auto_scroll=True,
                    controls=[ft.Text(f"Item {i}") for i in range(1, 101)],
                ),
            ],
        )
    )
    

    ft.app(main)

Perfect, it works! Thank you!

gcilli avatar Mar 25 '25 16:03 gcilli

However in case of using a Container it works

Yh, Container is not a scrollable. The issue here is caused by having a scrollable in another scrollable.

ndonkoHenri avatar Mar 25 '25 18:03 ndonkoHenri