OneSignal#
flet_onesignal.onesignal.OneSignal
#
OneSignal integration for Flet applications.
This is the main entry point for the OneSignal SDK. Add it to your page's services list to enable push notifications and in-app messaging.
Example
import flet as ft
import flet_onesignal as fos
async def main(page: ft.Page):
onesignal = fos.OneSignal(app_id="your-app-id")
page.services.append(onesignal) # Use services, NOT overlay!
# Request notification permission
granted = await onesignal.notifications.request_permission()
# Login a user
await onesignal.login("user-123")
ft.run(main)
Attributes:
| Name | Type | Description |
|---|---|---|
app_id |
str
|
Your OneSignal App ID. |
log_level |
Optional[OSLogLevel]
|
Optional SDK log level for console/logcat output. |
visual_alert_level |
Optional[OSLogLevel]
|
Optional SDK log level for visual alerts (iOS toast notifications). |
require_consent |
bool
|
Whether to require user consent before collecting data. |
Attributes#
app_id
class-attribute
instance-attribute
#
Your OneSignal App ID from the dashboard.
in_app_messages
property
#
Access the In-App Messages namespace for IAM triggers and control.
live_activities
property
#
Access the Live Activities namespace (iOS only).
log_level
class-attribute
instance-attribute
#
SDK log level for console/logcat output. Defaults to None (no logging).
notifications
property
#
Access the Notifications namespace for push notification management.
on_error
class-attribute
instance-attribute
#
Called when an error occurs in the SDK.
on_iam_click
class-attribute
instance-attribute
#
Called when the user clicks on an in-app message.
on_iam_did_dismiss
class-attribute
instance-attribute
#
Called after an in-app message is dismissed.
on_iam_did_display
class-attribute
instance-attribute
#
Called after an in-app message is displayed.
on_iam_will_dismiss
class-attribute
instance-attribute
#
Called before an in-app message is dismissed.
on_iam_will_display
class-attribute
instance-attribute
#
Called before an in-app message is displayed.
on_notification_click
class-attribute
instance-attribute
#
Called when the user taps on a notification.
on_notification_foreground
class-attribute
instance-attribute
#
Called when a notification is received while the app is in the foreground.
on_permission_change
class-attribute
instance-attribute
#
Called when the notification permission status changes.
on_push_subscription_change
class-attribute
instance-attribute
#
Called when the push subscription state changes.
on_user_change
class-attribute
instance-attribute
#
Called when the OneSignal user state changes.
require_consent
class-attribute
instance-attribute
#
Whether to require user consent before the SDK collects data (GDPR compliance).
user
property
#
Access the User namespace for identity, tags, aliases, email, SMS.
visual_alert_level
class-attribute
instance-attribute
#
SDK log level for visual alerts (iOS toast notifications). Defaults to None.
Functions#
consent_given
async
#
Indicate whether the user has given consent for data collection.
This method should be called after the user accepts or declines your privacy terms when require_consent is True.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
given
|
bool
|
True if the user gave consent, False otherwise. |
required |
login
async
#
Login to OneSignal with an external user ID.
This switches the user context to the specified user. If the user doesn't exist, a new user will be created.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
external_id
|
str
|
Your unique identifier for the user. |
required |
logout
async
#
Logout the current user.
After logout, a new anonymous device-scoped user will be created.