flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
10.4k stars 403 forks source link

OnScrollEvent for Listview don't work for flet 0.23.2 #3612

Closed logololo closed 4 days ago

logololo commented 3 weeks ago

Duplicate Check

Describe the bug

hi , OnScrollEvent for Listview don't work in flet 0.23.2 , it give an error

i use e: OnScrollEvent to print (e.pixels ) to find scrolling position ( delta )

it working fine in flet 0.22 on flet 0.23.1 it work fwhe i run main.py ( for test code) but when not when i build APK (when code is compiled) Copie d'écran_20240706_211616

Code sample

Logs ```python import flet as ft def main(page: ft.Page): page.title = "Scrolling ListView" def goo (e:ft.OnScrollEvent): print(f"{e.pixels}") print(f"{e.data}") global position position = e.pixels tx1.value= str(position) tx2.value= str(e.scroll_delta) tx1.update() tx2.update() return position lv = ft.ListView(expand=1, spacing=10, padding=20, auto_scroll=False , on_scroll = goo, ) count = 1 for i in range(0, 60): lv.controls.append(ft.Text(f"Line {count}" )) count += 1 tx1 = ft.Text( size = 20 , color = "cyan") tx2 = ft.Text( size = 20 , color = "yellow") page.add(tx1 ) page.add(tx2) page.add(lv) ft.app(target=main) ```

To reproduce

Task exception was never retrieved future: <Task finished name='Task-61' coro=<run_socket_server..on_event() done, defined at /home/vox/.local/lib/python3.10/site-packages/flet_runtime/app.py:217> exception=KeyError('sd')> Traceback (most recent call last): File "/home/vox/.local/lib/python3.10/site-packages/flet_runtime/app.py", line 219, in on_event await conn.sessions[e.sessionID].on_event_async( File "/home/vox/.local/lib/python3.10/site-packages/flet_core/page.py", line 905, in on_event_async await handler(ce) File "/home/vox/.local/lib/python3.10/site-packages/flet_core/event_handler.py", line 18, in fn ce = self.__result_converter(e) File "/home/vox/.local/lib/python3.10/site-packages/flet_core/scrollable_control.py", line 22, in self.on_scroll = EventHandler(lambda e: OnScrollEvent(e)) File "/home/vox/.local/lib/python3.10/site-packages/flet_core/scrollable_control.py", line 134, in init self.scroll_delta: Optional[float] = d["sd"] KeyError: 'sd'

Expected behavior

No response

Screenshots / Videos

Screenshots / Video demonstration [Upload media here]

Operating System

macOS

Operating system details

ubuntu 24 / Flutter 3.22.2

Flet version

Name: flet Version: 0.23.2 Summary: Flet for Python - easily build interactive multi-platform apps in Python Home-page: https://flet.dev Author: Appveyor Systems Inc. Author-email: hello@flet.dev License: Apache-2.0 Location: /home/vox/.local/lib/python3.10/site-packages Requires: cookiecutter, fastapi, flet-runtime, packaging, qrcode, uvicorn, watchdog Required-by:

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs ```console [Paste your logs here] ``` Task exception was never retrieved future: .on_event() done, defined at /home/vox/.local/lib/python3.10/site-packages/flet_runtime/app.py:217> exception=KeyError('sd')> Traceback (most recent call last): File "/home/vox/.local/lib/python3.10/site-packages/flet_runtime/app.py", line 219, in on_event await conn.sessions[e.sessionID].on_event_async( File "/home/vox/.local/lib/python3.10/site-packages/flet_core/page.py", line 905, in on_event_async await handler(ce) File "/home/vox/.local/lib/python3.10/site-packages/flet_core/event_handler.py", line 18, in fn ce = self.__result_converter(e) File "/home/vox/.local/lib/python3.10/site-packages/flet_core/scrollable_control.py", line 22, in self.__on_scroll = EventHandler(lambda e: OnScrollEvent(e)) File "/home/vox/.local/lib/python3.10/site-packages/flet_core/scrollable_control.py", line 134, in __init__ self.scroll_delta: Optional[float] = d["sd"] KeyError: 'sd'

Additional details

No response

ndonkoHenri commented 3 weeks ago

Sorry for the inconvenience. Issue has been raised in https://github.com/flet-dev/flet/issues/3566 and a fix has been implemented in #3551

ndonkoHenri commented 4 days ago

Issue has been fixed. Give it a try by installing the latest Flet prerelease: pip install flet --pre (https://pypi.org/project/flet/#history) Report if the issue persists.

logololo commented 4 days ago

hello ,

sorry , it s not working (i tried with 0.24.0.dev3170, 0.24.0.dev3171 and flet 0.24.0.dev3108)

the terminal shown nothing (o)

perhaps here / see in : self.scroll_delta: Optional[float] = d.get("sd") : [get fonction is not define ]

1

ndonkoHenri commented 3 days ago

What errors do you get?

logololo commented 3 days ago

nothing displayed on terminal , and it s not working :

i call this fonction when scroll on Listview :

def on_listview_scroll(e:ft.OnScrollEvent):

  position = f"{e.pixels}"
  print(f"{e.pixels}")

please see in : self.scroll_delta: Optional[float] = d.get("sd") => => ( "get " fonction is not define in scrollable_controle.py)

perhaps you forget to import somthing or defiine correctly the call of the "get" fonction

ndonkoHenri commented 3 days ago

"get " fonction is not define in scrollable_controle.py

Thats by the type checker, but don't mind it, it not an issue. Can you share the code you run and the result you have? Does the scrollable control scroll as expected?

ndonkoHenri commented 3 days ago

I also suggest you give another try to the latest prerelease. Maybe what I recently pushed will fix your issue.

logololo commented 3 days ago

hi ,

it work :) thank you for your work ... (Flet ver 0.24.0.dev3174)

simple test for delta scroll :

def on_listview_scroll(e:ft.OnScrollEvent):

position = f"{e.pixels}" print(f"{e.pixels}")

save screen

logololo commented 3 days ago

ps : i will try to build an APK for test and give you a feedback

logololo commented 1 day ago

hi ,

bad news , it s not working when you build apk for android :(

it s ok for linux (desktop) i tested it , but not working for androis , and i don't know what s wrong ....

ndonkoHenri commented 1 day ago

Saying it like this doesn't help anyone. 😅 Provide appropriate details on how to repro.

logololo commented 8 hours ago

hi , this is le code :

import flet as ft

def main(page: ft.Page): page.title = "Auto-scrolling ListView"

tx1 = ft.Text(value= " start position e.pixels = 0 " , color = "red" , size = 23 )
page.add(tx1)
def on_listview_scroll(e:ft.OnScrollEvent):

    position = f"{e.pixels}"
    print(position)
    tx1.value = f"Listview delta position {position}"
    tx1.update()

lv = ft.ListView( spacing=10, padding=20, expand = True ,  on_scroll= on_listview_scroll) 

count = 1

for i in range(0, 60):
    lv.controls.append(ft.Text(f"Line {count}"))
    count += 1

page.add(lv)

ft.app(target=main)