Skip to content

Flashlight

Examples#

Example 1#

example_1.py
import flet as ft

import flet_flashlight as ffl


def main(page: ft.Page):
    flashlight = ffl.Flashlight()
    page.services.append(flashlight)

    page.add(ft.TextButton("toggle", on_click=lambda _: flashlight.toggle()))


ft.run(main)

Flashlight #

Bases: Service

A control to use FlashLight. Works on iOS and Android.

Note

This control is a 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: KeyValue | None = None

on #

on = False

Whether the flashlight is currently turned on.

on_error #

on_error: ControlEventHandler[Flashlight] | None = None

Fires when an error occurs.

The data property of the event handler argument contains information on the error.

page #

page: Page | BasePage | None

The page 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.

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

build #

build()

Called once during control initialization to define its child controls. self.page is available in this method.

did_mount #

did_mount()

init #

init()

is_available #

is_available()

Checks if the flashlight is available on the device.

is_isolated #

is_isolated()

toggle #

toggle()

Toggles the flashlight on and off.

turn_off #

turn_off()

Turns the flashlight off.

turn_on #

turn_on()

Turns the flashlight on.

update #

update() -> None

will_unmount #

will_unmount()