Skip to content

Flashlight#

Control the device torch/flashlight in your Flet app via the flet-flashlight extension, built on top of Flutter's flashlight package.

Platform Support#

Platform Windows macOS Linux iOS Android Web
Supported

Usage#

Add flet-flashlight to your project dependencies:

uv add flet-flashlight
pip install flet-flashlight  # (1)!
  1. After this, you will have to manually add this package to your requirements.txt or pyproject.toml.

Example#

import flet_flashlight as ffl

import flet as ft


def main(page: ft.Page):
    async def toggle_flashlight():
        flashlight = ffl.Flashlight()
        await flashlight.toggle()

    page.add(ft.TextButton("toggle", on_click=toggle_flashlight))


ft.run(main)

Description#

Inherits: Service

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

Properties

  • on

    Whether the flashlight is currently turned on.

Events

Methods

  • is_available

    Checks if the flashlight is available on the device.

  • toggle

    Toggles the flashlight on and off.

  • turn_off

    Turns the flashlight off.

  • turn_on

    Turns the flashlight on.

Properties#

on #

on = False

Whether the flashlight is currently turned on.

Events#

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.

Methods#

is_available #

is_available()

Checks if the flashlight is available on the device.

toggle #

toggle()

Toggles the flashlight on and off.

turn_off #

turn_off()

Turns the flashlight off.

turn_on #

turn_on()

Turns the flashlight on.

See also: - FlashlightException - FlashlightEnableException - FlashlightDisableException