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

Optional on-demand creation of ListView.controls #3931

Closed
1 task done
florian3d opened this issue Sep 3, 2024 · 1 comment · Fixed by #4751
Closed
1 task done

Optional on-demand creation of ListView.controls #3931

florian3d opened this issue Sep 3, 2024 · 1 comment · Fixed by #4751
Assignees
Labels
controls enhancement Improvement/Optimization
Milestone

Comments

@florian3d
Copy link

Duplicate Check

Describe the bug

if slider number value is greater than last visible element order number or less than first visible element order number (the absolute delta depends on window size)

Code sample

Code
import flet

content = ['Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.', 'Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum']

def main(page: flet.Page):

    lv_items = flet.ListView(expand=1, spacing=0, padding=flet.padding.all(0.0), auto_scroll=False)
    page.add(lv_items)

    def bs_scroll_to_show(e):
        scroll_to_slider.max = 100
        scroll_to_slider.divisions = 100
        bs_scroll_to.open=True
        bs_scroll_to.update()
    
    def update_scroll_to_val(e):
        scroll_to_value.value = round(scroll_to_slider.value)
        scroll_to_value.update()

    def bs_scroll_to_dismiss(e):
        bs_scroll_to.open=False
        bs_scroll_to.update()

    def test_scroll_to(e):
        print(round(scroll_to_slider.value))
        # bs_scroll_to_dismiss(e)
        lv_items.scroll_to(key=str(round(scroll_to_slider.value)), duration=500)

    def scroll_to_start(e):
        lv_items.scroll_to(offset=0, duration=250)

    def scroll_to_end(e):
        lv_items.scroll_to(offset=-1, duration=250)

    for i in range(100):
        lv_items.controls.append(
            flet.ListTile(
                    leading=flet.Text(f'{str(i+1)}'.rjust(3, ' '), italic=True, no_wrap=False, text_align=flet.TextAlign.START, color=flet.colors.RED),
                    title=flet.Text(content[i%2], no_wrap=False, overflow=flet.TextOverflow.VISIBLE, font_family='verse_text', text_align=flet.TextAlign.LEFT),
                    dense=True,
                    visual_density=flet.VisualDensity.COMPACT,
                    key=str(i+1),
                    on_click=bs_scroll_to_show
                )
        )

    lv_items.update()

    scroll_to_value = flet.Text('1', size=24)
    scroll_to_slider = flet.Slider(min=1, max=1, value=1, divisions=100, on_change_end=test_scroll_to, on_change=update_scroll_to_val)

    bs_scroll_to = flet.BottomSheet(
        content=flet.Container(
                    content=flet.Column(
            [
                scroll_to_value,
                scroll_to_slider,
                flet.ElevatedButton("to start", on_click=scroll_to_start),
                flet.ElevatedButton("to end", on_click=scroll_to_end),
            ],
            spacing=10,
            tight=True,
            horizontal_alignment=flet.CrossAxisAlignment.CENTER,
            scroll=None
        ), padding=10
        ),
        on_dismiss=bs_scroll_to_dismiss
    )

    page.overlay.append(bs_scroll_to)
    page.update()

flet.app(target=main, view=flet.AppView.FLET_APP)

To reproduce

  1. run code
  2. click on item to show bottom menu
  3. use slider to set number bigger or smaller than last or first visible item order number

Expected behavior

to scroll to specific key (order number in this example is the same as key value)

Screenshots / Videos

Captures

[Upload media here]

scroll_to_test.mp4

Operating System

Windows

Operating system details

Windows 10 Pro

Flet version

flet-0.24.0 flet-core-0.24.0 flet-runtime-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

@OwenMcDonnell OwenMcDonnell self-assigned this Oct 22, 2024
@InesaFitsner InesaFitsner removed their assignment Oct 31, 2024
@ndonkoHenri
Copy link
Contributor

This issue could be solved by setting the cache_extent parameter of the ListView to a big value.

We will work on a proper solution, but you can try the above while waiting.

@ndonkoHenri ndonkoHenri added enhancement Improvement/Optimization controls labels Nov 27, 2024
@ndonkoHenri ndonkoHenri changed the title scroll_to method doesn't scroll to specific key of ListView layout component if specific item is not visible and ... Optional on-demand creation of ListView.controls Nov 27, 2024
@ndonkoHenri ndonkoHenri added this to the Flet v0.26.0 milestone Nov 28, 2024
@ndonkoHenri ndonkoHenri moved this from 🆕 New to 👀 In review in Flet Development Jan 21, 2025
@github-project-automation github-project-automation bot moved this from 👀 In review to ✅ Done in Flet Development Jan 22, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
controls enhancement Improvement/Optimization
Projects
Status: ✅ Done
5 participants
@OwenMcDonnell @InesaFitsner @florian3d @ndonkoHenri and others