HapticFeedback
Examples#
Basic Example#
import flet as ft
def main(page: ft.Page):
page.overlay.append(hf := ft.HapticFeedback())
async def heavy_impact():
await hf.heavy_impact()
async def medium_impact():
await hf.medium_impact()
async def light_impact():
await hf.light_impact()
async def vibrate():
await hf.vibrate()
page.add(
ft.ElevatedButton("Heavy impact", on_click=heavy_impact),
ft.ElevatedButton("Medium impact", on_click=medium_impact),
ft.ElevatedButton("Light impact", on_click=light_impact),
ft.ElevatedButton("Vibrate", on_click=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.
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_update
#
This method is called every time when this control is being updated.
Note
Make sure not to call/request an update()
here.
build
#
Called once during control initialization to define its child controls. self.page is available in this method.
heavy_impact
#
Provides a haptic feedback corresponding a collision impact with a heavy mass.
light_impact
#
Provides a haptic feedback corresponding a collision impact with a light mass.
medium_impact
#
Provides a haptic feedback corresponding a collision impact with a medium mass.