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

ListView(of ListTiles) display is buggy if ListTile height is smaller than 20 #453

Closed
YouJiacheng opened this issue Oct 7, 2022 · 4 comments · Fixed by #3396
Closed
Assignees
Labels
controls enhancement Improvement/Optimization

Comments

@YouJiacheng
Copy link
Contributor

from pathlib import Path

import flet
from flet import ListView, ListTile, Page, Text
from flet import UserControl

class DirectoryView(UserControl):
    def __init__(self, expand: bool | int | None = None):
        super().__init__(expand=expand, height=1000)
        self.current_working_dir = Path('~').expanduser()
        self.file_list = list(self.current_working_dir.iterdir())

    def build(self):
        selected: int | None = None

        def select():
            if selected is not None:
                item_list[selected].selected = True

        def deselect():
            if selected is not None:
                item_list[selected].selected = False

        def build_item(i: int, path: Path):
            def on_click(_):
                nonlocal selected
                deselect()
                selected = i
                select()
                self.update()
                
            return ListTile(title=Text(path.name, size=10), on_click=on_click, height=20)
        item_list: list[ListTile] = [build_item(i, path) for i, path in enumerate(self.file_list)]
        return ListView(item_list)


def main(page: Page):
    page.add(DirectoryView())


flet.app(target=main)

image
I clicked .cache, but actually .config was selected, because display was abnormal.

@YouJiacheng YouJiacheng changed the title ListView(of ListTiles) display is buggy if ListTile height is smaller than some value ListView(of ListTiles) display is buggy if ListTile height is smaller than 20 Oct 7, 2022
@YouJiacheng
Copy link
Contributor Author

Text size=20 + ListTile height=40 has NO problem.

@YouJiacheng
Copy link
Contributor Author

Replace ListTile with Container has NO problem. It seems that this is a ListTile bug.

@ndonkoHenri
Copy link
Contributor

ndonkoHenri commented May 15, 2024

ListTile.minTileHeight implemented in flutter/flutter#145244 should fix this issue.
Will add it once Flet bumps to Flutter 0.22.0

@ndonkoHenri ndonkoHenri added enhancement Improvement/Optimization controls labels May 15, 2024
@ndonkoHenri ndonkoHenri self-assigned this May 16, 2024
@ndonkoHenri ndonkoHenri moved this from 🆕 New to 👀 In review in Flet Development Jun 7, 2024
@ndonkoHenri ndonkoHenri linked a pull request Jun 7, 2024 that will close this issue
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Flet Development Jun 10, 2024
@ndonkoHenri
Copy link
Contributor

ndonkoHenri commented Jun 10, 2024

Simply set ListTile.min_height=20, in your case and the error will be fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controls enhancement Improvement/Optimization
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants