flet
flet copied to clipboard
Container doesn't dispatch ContainerTapEvent in ver 0.22.0
Description
Click event of Container is not ContainerTapEvent, so I can't get position like local_x
Code example to reproduce the issue:
self.map_container = ft.Container(content=self.map_img, width=self.large_map_width, height=self.large_map_width,
on_click=self.on_map_click, alignment=ft.alignment.top_left)
Describe the results you received:
<class 'flet_core.control_event.ControlEvent'> Future exception was never retrieved future: <Future finished exception=AttributeError("'ControlEvent' object has no attribute 'local_x'")> Traceback (most recent call last): File "concurrent\futures\thread.py", line 58, in run File "F:\code\workspace\StarRailOneDragon.env\venv\Lib\site-packages\flet_core\page.py", line 528, in wrapper handler(*args) File "F:\code\workspace\StarRailOneDragon\src\gui\world_patrol\world_patrol_draft_route_view.py", line 400, in on_map_click x = int(e.local_x / scale) ^^^^^^^^^
Issue doesn't happen in version 0.21.2
Describe the results you expected:
Get ContainerTapEvent
Additional information you deem important (e.g. issue happens only occasionally):
Always
Flet version (pip show flet
):
0.22.0
Give your requirements.txt
file (don't pip freeze
, instead give direct packages):
(The requirements)
Operating system:
Windows 10
Additional environment details:
Python 3.11.3
The functionality was moved to the new on_tap_down
instead.
on_click
still exists though, but no more has the position props.
Forgot to document that, sorry.
I would like to add something to this issue:
on_tap_down is not triggered if there is no on_click set
import flet as ft
def main(page: ft.Page):
page.vertical_alignment = ft.MainAxisAlignment.CENTER
page.horizontal_alignment = ft.CrossAxisAlignment.CENTER
t = ft.Text()
def container_click(e: ft.ContainerTapEvent):
t.value = f"local_x: {e.local_x}\nlocal_y: {e.local_y}\nglobal_x: {e.global_x}\nglobal_y: {e.global_y}"
t.update()
page.add(
ft.Column(
[
ft.Container(
content=ft.Text("Clickable inside container"),
alignment=ft.alignment.center,
bgcolor=ft.colors.GREEN_200,
width=200,
height=200,
border_radius=10,
on_tap_down=container_click,
#remove this on_click=lambda _: print()
),
t,
],
horizontal_alignment=ft.CrossAxisAlignment.CENTER,
),
)
ft.app(target=main)
on_tap_down is not triggered if there is no on_click set
Thanks for letting know. Will be fixed in the next release.
on_tap_down is not triggered if there is no on_click set
Thanks for letting know. Will be fixed in the next release. #3443