Skip to content

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.

data #

data: Any = skip_field()

Arbitrary data of any type.

key #

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

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 #

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.

shake_count_reset_time_ms #

shake_count_reset_time_ms: int = 3000

Time, in milliseconds, before shake count resets.

shake_slop_time_ms #

shake_slop_time_ms: int = 500

Minimum time between shakes, in milliseconds.

shake_threshold_gravity #

shake_threshold_gravity: Number = 2.7

Shake detection threshold, in Gs.

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()

init #

init()

is_isolated #

is_isolated()

update #

update() -> None

will_unmount #

will_unmount()