ShakeDetector
Examples#
Basic Example#
import flet as ft
def main(page: ft.Page):
page.services.append(
ft.ShakeDetector(
minimum_shake_count=2,
shake_slop_time_ms=300,
shake_count_reset_time_ms=1000,
on_shake=lambda _: page.add(ft.Text("Shake detected!")),
)
)
page.add(ft.Text("Shake your device!"))
ft.run(main)
ShakeDetector
#
Bases: Service
Detects phone shakes.
It is non-visual and should be added to
Page.services
list before it can be used.
minimum_shake_count
#
minimum_shake_count: int = 1
Number of shakes required before shake is triggered.
on_shake
#
on_shake: ControlEventHandler[ShakeDetector] | None = None
Called when a shake is detected.
page
#
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
.
shake_count_reset_time_ms
#
shake_count_reset_time_ms: int = 3000
Time, in milliseconds, before shake count resets.
before_update
#
This method is called every time when this control is being updated.
Note
Make sure not to call/request an update()
here.