flet-permission-handler#
A Flet extension that simplifies working with permissions in your app.
It is based on the permission_handler Flutter package and brings similar functionality to Flet, including:
- Requesting permissions at runtime
- Checking the current permission status (e.g., granted, denied)
- Redirecting users to system settings to manually grant permissions
Platform Support#
This package supports the following platforms:
Platform | Supported |
---|---|
Windows | ✅ |
macOS | ❌ |
Linux | ❌ |
iOS | ✅ |
Android | ✅ |
Web | ✅ |
Usage#
Installation#
To install the flet-permission-handler
package and add it to your project dependencies:
- After this, you will have to manually add this package to your
requirements.txt
orpyproject.toml
.
Example#
main.py
import flet as ft
import flet_permission_handler as fph
def main(page: ft.Page):
page.appbar = ft.AppBar(title="PermissionHandler Playground")
def show_snackbar(message: str):
page.show_dialog(ft.SnackBar(ft.Text(message)))
async def get_permission_status(e: ft.ControlEvent):
status = await p.get_status_async(fph.Permission.MICROPHONE)
show_snackbar(f"Microphone permission status: {status.name}")
async def request_permission(e: ft.ControlEvent):
status = await p.request_async(fph.Permission.MICROPHONE)
show_snackbar(f"Requested microphone permission: {status.name}")
async def open_app_settings(e: ft.ControlEvent):
show_snackbar("Opening app settings...")
await p.open_app_settings_async()
p = fph.PermissionHandler()
page.services.append(p) # (1)!
page.add(
ft.OutlinedButton("Open app settings", on_click=open_app_settings),
ft.OutlinedButton("Request Microphone permission", on_click=request_permission),
ft.OutlinedButton(
"Get Microphone permission status", on_click=get_permission_status
),
)
ft.run(main)
- The
PermissionHandler
instance must be added to the page'sservices
(notcontrols
) list to work properly.