flet-dev / flet

Flet enables developers to easily build realtime web, mobile and desktop apps in Python. No frontend experience required.
https://flet.dev
Apache License 2.0
9.43k stars 360 forks source link

Added Flash control to flet #3215

Open vv2006-mc opened 1 week ago

vv2006-mc commented 1 week ago

Added a new control called Flashlight used to turn on and off the flashlight of mobile

Sample Code:

import flet as ft

def main(page: ft.Page):
    flashlight = ft.Flashlight()
    flashText = ft.Text()
    page.overlay.append(flashlight)

    def flash_toggle(e):
        fl = flashlight.toggle()    
        if fl:
            flashText.value = "Flashlight on"
        else:
            flashText.value = "Flashlight off"

        flashText.update()

    page.add(
        ft.TextButton("Toggle Flashlight", on_click=flash_toggle),
        flashText,
    )

ft.app(target=main)
bleudev commented 1 week ago

Good idea! I want this PR to be merged

bleudev commented 1 week ago

Also Flash should be renamed to Flashlight, I think it'll be better

vv2006-mc commented 1 week ago

@bleudev Done! Anything else?

bleudev commented 1 week ago

@bleudev Done! Anything else?

Can you rename on() and off() methods to turn_on() and turn_off()? Also can you open PR in flet/website repository for Flashlight control?

vv2006-mc commented 1 week ago

Updated Example:


import flet as ft

def main(page: ft.Page):
    flashlight = ft.Flashlight()
    flashText = ft.Text()
    page.overlay.append(flashlight)

    def flash_toggle(e):
        fl = flashlight.toggle()
        if fl:
            flashText.value = "Flashlight on"
        else:
            flashText.value = "Flashlight off"

        flashText.update()

    def flash_on(e):
        fl = flashlight.turn_on()
        if fl:
            flashText.value = "Flashlight on"
        else:
            flashText.value = "There was an Error while turning on the Flashlight"

    flashText.update()

    def flash_off(e):
        fl = flashlight.turn_off()
        if fl:
            flashText.value = "There was an Error while turning on the Flashlight"
        else:
            flashText.value = "Flashlight on"

    flashText.update()

    page.add(
        ft.TextButton("Toggle Flashlight", on_click=flash_toggle),
        ft.TextButton("On Flashlight", on_click=flash_on),
        ft.TextButton("Off Flashlight", on_click=flash_off),
        flashText,
    )

ft.app(target=main)

Fixing the issue: #3188