Skip to content

bug: GestureDetector throwing an Event for on_secondary_tap, not TapEvent[GestureDetector] #5784

@Creeper19472

Description

@Creeper19472

Duplicate Check

Describe the bug

When I was writing the logic to handle the events thrown by GestureDetector, I found that when I performed a right-click operation, GestureDetector did not generate a TapEvent as described in the documentation, but a regular Event object, which caused my attempts to get the cursor coordinates to fail.

Code sample

Code
import flet as ft


def trigger_open_menu(
    event: ft.TapEvent[ft.GestureDetector] | ft.LongPressStartEvent[ft.GestureDetector],
):
    print(event)


async def main(page: ft.Page):
    # on web, disable default browser context menu
    if page.web:
        await page.browser_context_menu.disable()

    gd = ft.GestureDetector(
        on_long_press_start=trigger_open_menu,
        on_secondary_tap=trigger_open_menu,
        content=ft.ListTile(title=ft.Text("Test"), subtitle=ft.Text("Testing")),
    )
    page.add(gd)


if __name__ == "__main__":
    ft.run(main)

To reproduce

  1. Run the repro code
  2. Long press the ListTile
  3. Right-click the ListTile
  4. See the console output

Expected behavior

When I right-click, the console should output TapEvent(...).

Screenshots / Videos

Captures Image

Operating System

Windows

Operating system details

Windows 11 25H2 (26200.6899)

Flet version

0.70.0.dev6555

Regression

I'm not sure / I don't know

Suggestions

No response

Logs

Logs
python3 gesturedetector_test.py

LongPressStartEvent(name='long_press_start', data=None, local_position=Offset(x=40.0, y=38.0), global_position=Offset(x=50.0, y=48.0))
Event(name='secondary_tap', data=None)

Additional details

No response

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions