ShakeDetector
Detects phone shakes.
Inherits: Service
Properties
minimum_shake_count- Number of shakes required before shake is triggered.shake_count_reset_time_ms- Time, in milliseconds, before shake count resets.shake_slop_time_ms- Minimum time between shakes, in milliseconds.shake_threshold_gravity- Shake detection threshold, in Gs.
Events
on_shake- Called when a shake is detected.
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.SafeArea(
content=ft.Column(
controls=[ft.Text("Shake your device!")],
),
)
)
if __name__ == "__main__":
ft.run(main)
Properties
minimum_shake_countclass-attributeinstance-attribute
minimum_shake_count: int = 1Number of shakes required before shake is triggered.
shake_count_reset_time_msclass-attributeinstance-attribute
shake_count_reset_time_ms: int = 3000Time, in milliseconds, before shake count resets.
shake_slop_time_msclass-attributeinstance-attribute
shake_slop_time_ms: int = 500Minimum time between shakes, in milliseconds.
Events
on_shakeclass-attributeinstance-attribute
on_shake: Optional[ControlEventHandler[ShakeDetector]] = NoneCalled when a shake is detected.