Permission Handler
Manages runtime permissions in Flet applications using the flet-permission-handler extension, which is powered by Flutter's permission_handler.
Platform Support
| Platform | Windows | macOS | Linux | iOS | Android | Web | |---|---|---|---|---|---|---| | Supported | ✅ | ❌ | ❌ | ✅ | ✅ | ✅ |
Installation
Add flet-permission-handler to your project dependencies:
uv: uv add flet-permission-handler
pip: pip install flet-permission-handler
After installation, manually add the package to your requirements.txt or pyproject.toml.
**Note:** On mobile platforms, permissions must also be declared in the native project files. Refer to Flet publish docs for details.
Description
Inherits from flet.Service.
Manages permissions for the application.
Raises:
FletUnsupportedPlatformException: If the platform is not supported.Methods
#### get_status(permission: Permission) -> PermissionStatus | None
Gets the current status of the given permission.
permission: The Permission enum to check the status for.
PermissionStatus enum if the status is known, otherwise None.#### open_app_settings() -> bool
Opens the app settings page.
True if the app settings page could be opened, otherwise False.#### request(permission: Permission) -> PermissionStatus | None
Requests the user for access to the permission if access hasn't already been granted.
permission: The Permission enum to request.
PermissionStatus after the request, or None if the request was not successful.Example Usage
import flet as ft
import flet_permission_handler as fphdef 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.Event[ft.OutlinedButton]):
status = await ph.get_status(fph.Permission.MICROPHONE)
show_snackbar(f"Microphone permission status: {status.name}")
async def request_permission(e: ft.Event[ft.OutlinedButton]):
status = await ph.request(fph.Permission.MICROPHONE)
show_snackbar(f"Requested microphone permission: {status.name}")
async def open_app_settings(e: ft.Event[ft.OutlinedButton]):
show_snackbar("Opening app settings...")
await ph.open_app_settings()
ph = fph.PermissionHandler()
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)
Types
Permission: Enum for specifying permissions (e.g., MICROPHONE).PermissionStatus: Enum representing the status of a permission (e.g., GRANTED, DENIED, PERMANENTLY_DENIED, LIMITED, PROMPT).