Skip to content

HapticFeedback

Examples#

Basic Example#

import flet as ft


def main(page: ft.Page):
    page.overlay.append(hf := ft.HapticFeedback())

    page.add(
        ft.ElevatedButton("Heavy impact", on_click=lambda _: hf.heavy_impact()),
        ft.ElevatedButton("Medium impact", on_click=lambda _: hf.medium_impact()),
        ft.ElevatedButton("Light impact", on_click=lambda _: hf.light_impact()),
        ft.ElevatedButton("Vibrate", on_click=lambda _: hf.vibrate()),
    )


ft.run(main)

HapticFeedback #

Bases: Service

Allows access to the haptic feedback interface on the device.

It is non-visual and should be added to Page.services list before it can be used.

data #

data: Any = skip_field()

Arbitrary data of any type.

key #

key: (
    str | int | float | bool | ValueKey | ScrollKey | None
) = None

page #

page: Page | PageView | None

The page (of type Page or PageView) to which this control belongs to.

parent #

parent: BaseControl | None

The direct ancestor(parent) of this control.

It defaults to None and will only have a value when this control is mounted (added to the page tree).

The Page control (which is the root of the tree) is an exception - it always has parent=None.

before_event #

before_event(e: ControlEvent)

before_update #

before_update()

This method is called every time when this control is being updated.

Note

Make sure not to call/request an update() here.

did_mount #

did_mount()

heavy_impact #

heavy_impact()

Provides a haptic feedback corresponding a collision impact with a heavy mass.

heavy_impact_async #

heavy_impact_async()

Provides a haptic feedback corresponding a collision impact with a heavy mass.

init #

init()

is_isolated #

is_isolated()

light_impact #

light_impact()

Provides a haptic feedback corresponding a collision impact with a light mass.

light_impact_async #

light_impact_async()

Provides a haptic feedback corresponding a collision impact with a light mass.

medium_impact #

medium_impact()

Provides a haptic feedback corresponding a collision impact with a medium mass.

medium_impact_async #

medium_impact_async()

Provides a haptic feedback corresponding a collision impact with a medium mass.

selection_click #

selection_click()

TBD

selection_click_async #

selection_click_async()

TBD

update #

update() -> None

vibrate #

vibrate()

Provides vibration haptic feedback to the user for a short duration.

vibrate_async #

vibrate_async()

Provides vibration haptic feedback to the user for a short duration.

will_unmount #

will_unmount()