Flashlight Service

Overview

  • The Flashlight service allows controlling the device's torch/flashlight within a Flet application.
  • It is an extension built upon Flutter's flashlight package.
  • Inherits from flet.Service.
  • Platform Support

  • **Supported Platforms:** iOS, Android
  • **Unsupported Platforms:** Windows, macOS, Linux, Web
  • Installation

    1. **Add Dependency:** - Using uv:

         uv add flet-flashlight
         
    - Using pip:
         pip install flet-flashlight
         
    2. **Project Configuration:** - Manually add flet-flashlight to your requirements.txt or pyproject.toml file.

    Usage Example

    import flet as ft
    import flet_flashlight as ffl

    def main(page: ft.Page): async def turn_on_flashlight(): await ffl.Flashlight().on()

    async def turn_off_flashlight(): await ffl.Flashlight().off()

    page.add( ft.Button("Turn On Flashlight", on_click=turn_on_flashlight), ft.Button("Turn Off Flashlight", on_click=turn_off_flashlight), )

    ft.run(main)

    Methods

  • **is_available()**
  • - **Type:** async - **Description:** Checks if the flashlight hardware is available on the device. - **Usage:** await ffl.Flashlight().is_available()

  • **on()**
  • - **Type:** async - **Description:** Turns the device's flashlight on. - **Usage:** await ffl.Flashlight().on()

  • **off()**
  • - **Type:** async - **Description:** Turns the device's flashlight off. - **Usage:** await ffl.Flashlight().off()