### Install Flutter Dependencies
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-pods/README.md
Run this command to fetch all the necessary Flutter packages for the project.
```bash
flutter pub get
```
--------------------------------
### Install iOS Dependencies
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Run `flutter pub get` to fetch Dart packages and then `pod install` in the `ios` directory to manage native iOS dependencies. This is crucial for setting up the CocoaPods workspace and build phases.
```sh
flutter pub get
cd ios && pod install
```
--------------------------------
### Copy .env.example to .env
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-no-location/README.md
Copy the example environment file to a new file named .env. This file will store your OneSignal App ID.
```sh
cp .env.example .env
```
--------------------------------
### Install iOS CocoaPods Dependencies
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-pods/README.md
Navigate to the iOS directory and install CocoaPods dependencies. This is required for iOS builds.
```bash
cd ios && pod install && cd ..
```
--------------------------------
### Initialize OneSignal SDK (Flutter)
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Replace the old `setAppId` method with the new `initialize` method for SDK setup. Ensure this is done in your app's main entry point.
```flutter
OneSignal.shared.setAppId("YOUR_ONESIGNAL_APP_ID");
```
```flutter
OneSignal.initialize("YOUR_ONESIGNAL_APP_ID");
```
--------------------------------
### Info.plist for iOS Notification Service Extension
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Configure the Info.plist file for the Notification Service Extension. Ensure all standard CFBundle* keys are present for proper simulator installation and operation.
```xml
CFBundleDisplayName
OneSignalNotificationServiceExtension
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
$(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
$(PRODUCT_NAME)
CFBundlePackageType
$(PRODUCT_BUNDLE_PACKAGE_TYPE)
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
$(CURRENT_PROJECT_VERSION)
NSExtension
NSExtensionPointIdentifier
com.apple.usernotifications.service
NSExtensionPrincipalClass
$(PRODUCT_MODULE_NAME).NotificationService
```
--------------------------------
### Get Push Subscription Details (Flutter)
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Retrieve the ID, token, and opt-in status of the current device's push subscription using the `OneSignal.User.pushSubscription` property.
```flutter
var id = OneSignal.User.pushSubscription.id;
var token = OneSignal.User.pushSubscription.token;
var optedIn = OneSignal.User.pushSubscription.optedIn;
```
--------------------------------
### Get User Tags
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Retrieve all local tags currently associated with the user. This returns a map of key-value pairs.
```dart
OneSignal.User.getTags();
```
--------------------------------
### Get User IDs
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Retrieve the nullable OneSignal ID or External ID for the current user.
```APIDOC
## OneSignal.User.getOnesignalId
### Description
Returns the nullable OneSignal ID for the current user.
### Method
`await OneSignal.User.getOnesignalId()`
### Parameters
None
### Request Example
```dart
var onesignalId = await OneSignal.User.getOnesignalId();
```
### Response
- **onesignalId** (String?) - The nullable OneSignal ID.
## OneSignal.User.getExternalId
### Description
Returns the nullable External ID for the current user.
### Method
`await OneSignal.User.getExternalId()`
### Parameters
None
### Request Example
```dart
var externalId = await OneSignal.User.getExternalId();
```
### Response
- **externalId** (String?) - The nullable External ID.
```
--------------------------------
### Disable OneSignal Location with CocoaPods
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/README.md
Navigate to the iOS directory, deintegrate CocoaPods, remove Pods and Podfile.lock, and then install pods with the ONESIGNAL_DISABLE_LOCATION variable set to true.
```sh
cd ios
pod deintegrate
rm -rf Pods Podfile.lock
ONESIGNAL_DISABLE_LOCATION=true pod install
```
--------------------------------
### Info.plist Configuration for Live Activities
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Configure the Info.plist file to enable Live Activities by adding the 'NSSupportsLiveActivities' key.
```xml
CFBundleDisplayName
OneSignalWidgetExtension
CFBundleExecutable
$(EXECUTABLE_NAME)
CFBundleIdentifier
$(PRODUCT_BUNDLE_IDENTIFIER)
CFBundleInfoDictionaryVersion
6.0
CFBundleName
$(PRODUCT_NAME)
CFBundlePackageType
$(PRODUCT_BUNDLE_PACKAGE_TYPE)
CFBundleShortVersionString
$(MARKETING_VERSION)
CFBundleVersion
$(CURRENT_PROJECT_VERSION)
NSSupportsLiveActivities
NSExtension
NSExtensionPointIdentifier
com.apple.widgetkit-extension
```
--------------------------------
### Get Push Token in Flutter
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Access the readonly push token for the current user.
```dart
var token = OneSignal.User.pushSubscription.token
```
--------------------------------
### Run Flutter Application
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-pods/README.md
Execute this command to build and run the Flutter demo application on a connected device or emulator.
```bash
flutter run
```
--------------------------------
### Get Push Subscription ID in Flutter
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Access the readonly push subscription ID for the current user.
```dart
var id = OneSignal.User.pushSubscription.id
```
--------------------------------
### Initialize OneSignal SDK
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Initializes the OneSignal SDK. This should be called during application startup.
```dart
OneSignal.initialize("YOUR_ONESIGNAL_APP_ID");
```
--------------------------------
### Initialize OneSignal SDK and Set Options
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Initialize the OneSignal SDK and configure Live Activities, In-App Messages, and Location sharing. This should be done after restoring SDK state from SharedPreferences.
```dart
OneSignal.Debug.setLogLevel(OSLogLevel.verbose);
OneSignal.consentRequired(prefs.consentRequired);
OneSignal.consentGiven(prefs.privacyConsent);
await OneSignal.initialize(appId);
OneSignal.LiveActivities.setupDefault(
options: LiveActivitySetupOptions(
enablePushToStart: true,
enablePushToUpdate: true,
),
);
OneSignal.InAppMessages.paused(prefs.iamPaused);
OneSignal.Location.setShared(prefs.locationShared);
```
--------------------------------
### Get OneSignal User ID
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Retrieve the nullable OneSignal ID for the current user. This ID is assigned by OneSignal upon user registration.
```dart
await OneSignal.User.getOnesignalId();
```
--------------------------------
### Run Android Demo with No-Location
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-no-location/README.md
Execute the demo on Android using the provided helper script. This command ensures the app runs without requesting fine or coarse location permissions in the Android manifest.
```sh
./run.sh -d android
```
--------------------------------
### OneSignal Initialization
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Initializes the OneSignal SDK. This method should be called during the application's startup.
```APIDOC
## OneSignal.initialize
### Description
Initializes the OneSignal SDK. This should be called during startup of the application.
### Method
`OneSignal.initialize(String appId)`
### Parameters
#### Path Parameters
- **appId** (String) - Required - Your OneSignal App ID.
```
--------------------------------
### Get External User ID
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Retrieve the nullable external ID associated with the current user. This is an ID you provide to link OneSignal users to your own user accounts.
```dart
await OneSignal.User.getExternalId();
```
--------------------------------
### iOS Info.plist Configuration
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Configuration for Info.plist on iOS to enable Live Activities and background notification handling.
```xml
- `ios/Runner/Info.plist` includes:
- `NSSupportsLiveActivities` (enables ActivityKit-backed Live Activities).
- Location usage strings (`NSLocationWhenInUseUsageDescription`, etc.).
- `UIBackgroundModes` containing `remote-notification` for silent push handling.
```
--------------------------------
### Click Listener
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Set up a listener to detect when a user opens a notification.
```APIDOC
## Click Listener
### `OneSignal.Notifications.addClickListener(listener);`
**Description**: Sets a listener that is invoked every time a user opens a notification.
**Example Usage**:
```dart
OneSignal.Notifications.addClickListener((event) {
print('NOTIFICATION CLICK LISTENER CALLED WITH EVENT: $event');
});
```
### `OneSignal.Notifications.removeClickListener(listener);`
**Description**: Removes a previously added click listener.
```
--------------------------------
### OneSignal Flutter SDK Demo File Structure
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Overview of the directory structure for the OneSignal Flutter SDK demo application.
```plaintext
examples/demo/
├── lib/
│ ├── main.dart
│ ├── theme.dart
│ ├── models/
│ │ ├── user_data.dart
│ │ ├── notification_type.dart
│ │ └── in_app_message_type.dart
│ ├── services/
│ │ ├── onesignal_api_service.dart
│ │ ├── preferences_service.dart
│ │ └── tooltip_helper.dart
│ ├── viewmodels/
│ │ └── app_viewmodel.dart
│ ├── screens/
│ │ ├── home_screen.dart
│ │ └── secondary_screen.dart
│ └── widgets/
│ ├── section_card.dart
│ ├── toggle_row.dart
│ ├── action_button.dart
│ ├── app_text_field.dart
│ ├── list_widgets.dart
│ ├── dialogs.dart
│ └── sections/
│ ├── app_section.dart
│ ├── user_section.dart
│ ├── push_section.dart
│ ├── send_push_section.dart
│ ├── in_app_section.dart
│ ├── send_iam_section.dart
│ ├── aliases_section.dart
│ ├── emails_section.dart
│ ├── sms_section.dart
│ ├── tags_section.dart
│ ├── outcomes_section.dart
│ ├── triggers_section.dart
│ ├── custom_events_section.dart
│ ├── live_activities_section.dart
│ └── location_section.dart
├── assets/
│ └── onesignal_logo.svg
├── android/
│ └── app/
│ └── build.gradle.kts
├── ios/
│ ├── OneSignalWidget/
│ └── OneSignalNotificationServiceExtension/
├── .env
└── pubspec.yaml
```
--------------------------------
### OneSignal Widget Bundle Entry Point
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
The main entry point for the WidgetKit bundle, defining the widget to be displayed. This snippet sets up the OneSignalWidgetLiveActivity as the primary widget.
```swift
import WidgetKit
import SwiftUI
@main
struct OneSignalWidgetBundle: WidgetBundle {
var body: some Widget {
OneSignalWidgetLiveActivity()
}
}
```
--------------------------------
### Enable Live Activities and Background Push in Info.plist
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Add NSSupportsLiveActivities and UIBackgroundModes to your app's Info.plist for Live Activities and remote notification support.
```xml
NSSupportsLiveActivities
UIBackgroundModes
remote-notification
```
--------------------------------
### Run iOS Demo with No-Location
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-no-location/README.md
Execute the demo on iOS using the provided helper script. The script ensures native dependencies are resolved with ONESIGNAL_DISABLE_LOCATION set to true, preventing the inclusion of the location module.
```sh
./run.sh -d ios
```
--------------------------------
### Run iOS App with Specific Simulator
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-pods/README.md
Use this helper script to run the iOS application on a specific simulator.
```bash
../run-ios.sh
```
--------------------------------
### Load Initial UI State from Preferences
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Load the initial UI state for the application from SharedPreferences. If an external user ID is present, log the user into the OneSignal SDK.
```dart
_consentRequired = _prefs.consentRequired;
_privacyConsentGiven = _prefs.privacyConsent;
_externalUserId = _prefs.externalUserId;
_iamPaused = _prefs.iamPaused;
_locationShared = _prefs.locationShared;
if (_externalUserId != null) {
OneSignal.login(_externalUserId!);
}
```
--------------------------------
### Swift Widget for Live Activities
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Implement the Live Activity widget using Swift and the OneSignal SDK. This code handles displaying order status and progress.
```swift
import ActivityKit
import WidgetKit
import SwiftUI
import OneSignalLiveActivities
@available(iOS 16.2, *)
struct OneSignalWidgetLiveActivity: Widget {
private func statusIcon(for status: String) -> String {
switch status {
case "on_the_way": return "box.truck.fill"
case "delivered": return "checkmark.circle.fill"
default: return "bag.fill"
}
}
private func statusColor(for status: String) -> Color {
switch status {
case "on_the_way": return .blue
case "delivered": return .green
default: return .orange
}
}
private func statusLabel(for status: String) -> String {
switch status {
case "on_the_way": return "On the Way"
case "delivered": return "Delivered"
default: return "Preparing"
}
}
var body: some WidgetConfiguration {
ActivityConfiguration(for: DefaultLiveActivityAttributes.self) { context in
let orderNumber = context.attributes.data["orderNumber"]?.asString() ?? "Order"
let status = context.state.data["status"]?.asString() ?? "preparing"
let message = context.state.data["message"]?.asString() ?? "Your order is being prepared"
let eta = context.state.data["estimatedTime"]?.asString() ?? ""
VStack(spacing: 10) {
HStack {
Text(orderNumber)
.font(.caption)
.foregroundColor(.gray)
Spacer()
if !eta.isEmpty {
Text(eta)
.font(.caption)
.foregroundColor(.white.opacity(0.7))
}
}
HStack(spacing: 12) {
Image(systemName: statusIcon(for: status))
.font(.title2)
.foregroundColor(statusColor(for: status))
VStack(alignment: .leading, spacing: 2) {
Text(statusLabel(for: status))
.font(.headline)
.foregroundColor(.white)
Text(message)
.font(.subheadline)
.foregroundColor(.white.opacity(0.8))
.lineLimit(1)
}
Spacer()
}
DeliveryProgressBar(status: status)
}
.padding()
.activityBackgroundTint(Color(red: 0.11, green: 0.13, blue: 0.19))
.activitySystemActionForegroundColor(.white)
} dynamicIsland: { context in
let status = context.state.data["status"]?.asString() ?? "preparing"
let message = context.state.data["message"]?.asString() ?? "Preparing"
let eta = context.state.data["estimatedTime"]?.asString() ?? ""
```
--------------------------------
### Add OneSignal Widget Extension Target
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Add this target to your Podfile for Live Activities integration.
```ruby
target 'OneSignalWidgetExtension' do
use_frameworks!
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end
```
--------------------------------
### Set iOS Platform Version
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Uncomment or add the platform line in your Podfile to specify the minimum iOS version.
```ruby
platform :ios, '13.0'
```
--------------------------------
### Push Subscription Methods
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Methods to manage push notification opt-in and opt-out status.
```APIDOC
## Push Subscription Methods
### Description
Methods to manage push notification opt-in and opt-out status, and to observe changes in the subscription state.
### Methods
#### `optIn()`
- **Description**: Call this method to receive push notifications on the device or to resume receiving of push notifications after calling `optOut`. If needed, this method will prompt the user for push notifications permission.
#### `optOut()`
- **Description**: If at any point you want the user to stop receiving push notifications on the current device (regardless of system-level permission status), you can call this method to opt out.
#### `addObserver(OnPushSubscriptionChangeObserver observer)`
- **Description**: Adds an observer to listen for changes in the push subscription state. The observer will be called with an `OSPushSubscriptionChangedState` object containing the previous and current states.
- **Example**:
```dart
OneSignal.User.pushSubscription.addObserver((state) {
OSPushSubscriptionChangedState current = state.current;
OSPushSubscriptionChangedState previous = state.previous;
if (state.current.optedIn) {
/// Respond to new state
}
});
```
#### `removeObserver(observer)`
- **Description**: Removes a previously added push subscription observer.
```
--------------------------------
### Run Android App with Specific Emulator
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-pods/README.md
Use this helper script to run the Android application on a specific emulator by its AVD name.
```bash
../run-android.sh
```
--------------------------------
### Opt In to Push Notifications (Flutter)
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Use the `optIn` method on the push subscription to prompt the user for notification permissions and enable receiving push notifications.
```flutter
OneSignal.User.pushSubscription.optIn();
```
--------------------------------
### Login User (Flutter)
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Use the `login` method to associate a device's push subscription with a user. This method creates the user if they don't exist or updates an existing one.
```flutter
OneSignal.login("EXTERNAL_ID");
```
--------------------------------
### Configure Runner Entitlements for Push Notifications and App Groups
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Create or update Runner.entitlements to enable push notifications and define an App Group for extensions.
```xml
aps-environment
development
com.apple.security.application-groups
group.com.onesignal.example.onesignal
```
--------------------------------
### Enter Live Activity
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Associates an activityId with a live activity temporary push token on OneSignal's server. This is an iOS-only feature.
```APIDOC
## enterLiveActivity
### Description
*(iOS only) Entering a Live Activity associates an `activityId` with a live activity temporary push `token` on OneSignal's server. The activityId is then used with the OneSignal REST API to update one or multiple Live Activities at one time.*
### Method Signature
`OneSignal.LiveActivities.enterLiveActivity(String activityId, String token);`
### Parameters
#### Path Parameters
- **activityId** (String) - Required - The unique identifier for the Live Activity.
- **token** (String) - Required - The temporary push token for the Live Activity.
### Request Example
```dart
OneSignal.LiveActivities.enterLiveActivity("ACTIVITY_ID", "TOKEN");
```
```
--------------------------------
### Request Notification Permission
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Prompts the user to grant push notification permission. Set `fallbackToSettings` to true to open system settings if permission is denied.
```dart
OneSignal.Notifications.requestPermission(true);
```
--------------------------------
### Generate App Icons
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Use the flutter_launcher_icons package to generate Android and iOS app icons. Remove the generated PNG asset afterwards if desired.
```bash
dart run flutter_launcher_icons
rm assets/onesignal_logo_icon_padded.png
```
--------------------------------
### Add Multiple User Tags
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add or update multiple tags for the current user. Existing tags with the same keys will be replaced.
```dart
OneSignal.User.addTags({"KEY_01": "VALUE_01", "KEY_02": "VALUE_02"});
```
--------------------------------
### Add Multiple User Aliases
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Set multiple aliases for the current user. Any existing aliases with the same labels will be overwritten.
```dart
OneSignal.User.addAliases({"ALIAS_LABEL_01": "ALIAS_ID_01", "ALIAS_LABEL_02": "ALIAS_ID_02"});
```
--------------------------------
### Opt In to Push Notifications in Flutter
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Call this method to enable push notifications or resume them after opting out. It may prompt the user for permission.
```dart
OneSignal.User.pushSubscription.optIn()
```
--------------------------------
### Add OneSignal Notification Service Extension Target
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Add this target to your Podfile to handle background notification processing.
```ruby
target 'OneSignalNotificationServiceExtension' do
use_frameworks!
pod 'OneSignalXCFramework', '>= 5.0.0', '< 6.0'
end
```
--------------------------------
### Location Namespace
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Access location-scoped functionality via `OneSignal.Location`.
```APIDOC
## OneSignal.Location.isShared()
### Description
Checks if location is currently shared with OneSignal.
### Method
`isShared()`
### Endpoint
N/A (SDK Method)
### Response
- **isShared** (boolean) - True if location is shared, false otherwise.
```
```APIDOC
## OneSignal.Location.setShared(bool shared)
### Description
Enables or disables location sharing with OneSignal.
### Method
`setShared(bool shared)`
### Endpoint
N/A (SDK Method)
### Parameters
#### Path Parameters
N/A
#### Query Parameters
N/A
#### Request Body
- **shared** (boolean) - Required - Set to true to enable location sharing, false to disable.
```
```APIDOC
## OneSignal.Location.requestPermission()
### Description
Manually prompts the user for location permissions to enable geotagging for location-based notifications.
### Method
`requestPermission()`
### Endpoint
N/A (SDK Method)
### Response
- **permissionGranted** (boolean) - True if permission was granted, false otherwise.
```
--------------------------------
### Set User Language
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Set the 2-character language for the current user. Use standard ISO 639-1 language codes.
```dart
OneSignal.User.setLanguage("en");
```
--------------------------------
### Flutter Project Dependencies
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
List of dependencies for a Flutter project using the OneSignal SDK, including core Flutter packages, OneSignal, and utility libraries.
```yaml
dependencies:
flutter:
sdk: flutter
onesignal_flutter:
path: ../../
provider: ^6.1.0
shared_preferences: ^2.3.0
http: ^1.2.0
url_launcher: ^6.2.0
flutter_svg: ^2.0.0
flutter_dotenv: ^5.2.1
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^5.0.0
flutter_launcher_icons: ^0.14.3
flutter_launcher_icons:
android: true
ios: true
remove_alpha_ios: true
image_path: "assets/onesignal_logo_icon_padded.png"
adaptive_icon_background: "#FFFFFF"
adaptive_icon_foreground: "assets/onesignal_logo_icon_padded.png"
```
--------------------------------
### Update Swift Import Statement
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Replace the old OneSignal import statement with the new one for Swift projects.
```swift
// Replace the old import statement
import OneSignal
// With the new import statement
import OneSignalFramework
```
--------------------------------
### Add Email Subscription
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add a new email subscription for the current user. This associates an email address with the user for communication.
```dart
OneSignal.User.addEmail("customer@company.com");
```
--------------------------------
### Dynamic Island Expanded and Compact Views
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Defines the UI for the expanded and compact states of a Dynamic Island notification. This includes regions for leading, center, trailing, and bottom content.
```swift
return DynamicIsland {
DynamicIslandExpandedRegion(.leading) {
Image(systemName: statusIcon(for: status))
.font(.title2)
.foregroundColor(statusColor(for: status))
}
DynamicIslandExpandedRegion(.center) {
Text(statusLabel(for: status))
.font(.headline)
}
DynamicIslandExpandedRegion(.trailing) {
if !eta.isEmpty {
Text(eta)
.font(.caption)
.foregroundColor(.secondary)
}
}
DynamicIslandExpandedRegion(.bottom) {
Text(message)
.font(.caption)
.foregroundColor(.secondary)
}
} compactLeading: {
Image(systemName: statusIcon(for: status))
.foregroundColor(statusColor(for: status))
} compactTrailing: {
Text(statusLabel(for: status))
.font(.caption)
} minimal: {
Image(systemName: statusIcon(for: status))
.foregroundColor(statusColor(for: status))
}
}
}
}
```
--------------------------------
### Foreground Will Display Listener
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Listen for notifications that are about to be displayed while the app is in the foreground. Allows modification or prevention of display.
```APIDOC
## Foreground Will Display Listener
### `OneSignal.Notifications.addForegroundWillDisplayListener(listener);`
**Description**: Adds a listener that executes before a notification is displayed while the app is in focus. This allows for reading notification data, modifying it, or deciding whether to display the notification. Note that this runs after the Notification Service Extension.
**Example Usage**:
```dart
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
/// preventDefault to not display the notification
event.preventDefault();
/// Do async work
/// notification.display() to display after preventing default
event.notification.display();
});
```
### `OneSignal.Notifications.removeForegroundWillDisplayListener(listener);`
**Description**: Removes a previously added foreground will display listener.
```
--------------------------------
### Run Flutter App on Specific Device
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-pods/README.md
Specify a device ID to run the Flutter application on a particular connected device or simulator.
```bash
flutter run -d
```
--------------------------------
### User State Observer
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add or remove an observer to listen for changes in the user's state, such as OneSignal ID or external ID.
```APIDOC
## OneSignal.User.addObserver
### Description
Add a User State observer which contains the nullable onesignalId and externalId. The listener will be fired when these values change.
### Method
`OneSignal.User.addObserver(OnUserChangeObserver observer)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addObserver((state) {
var userState = state.jsonRepresentation();
print('OneSignal user changed: $userState');
});
```
### Response
None
## OneSignal.User.removeObserver
### Description
Remove a user state observer that has been previously added.
### Method
`OneSignal.User.removeObserver(OnUserChangeObserver observer)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
// Assuming 'observer' is the function previously passed to addObserver
OneSignal.User.removeObserver(observer);
```
### Response
None
```
--------------------------------
### OneSignal Login
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Logs a user into OneSignal using an external ID. This action switches the user context and handles existing or new user creation, including subscription transfers.
```APIDOC
## OneSignal.login
### Description
Logs in to OneSignal under the user identified by the provided externalId. This switches the user context to that specific user. If the externalId exists, the user is retrieved. If it does not exist, a new user is created. Push notification and in-app messaging subscriptions are automatically transferred.
### Method
`OneSignal.login(String externalId)`
### Parameters
#### Path Parameters
- **externalId** (String) - Required - The external ID of the user to log in.
```
--------------------------------
### User Language Management
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Set the 2-character language for the current user. This affects how the user perceives localized content.
```APIDOC
## OneSignal.User.setLanguage
### Description
Set the 2-character language for this user.
### Method
`OneSignal.User.setLanguage(String languageCode)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.setLanguage("en");
```
### Response
None
```
--------------------------------
### Notification Permissions
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Access and request push notification permissions. Includes checking current permission status, determining if a prompt will be shown, and requesting permission with an option to fall back to settings.
```APIDOC
## Notification Permissions
### `var permission = OneSignal.Notifications.permission`
**Description**: Checks if the app currently has push notification permission.
### `var permissionNative = await OneSignal.Notifications.permissionNative()`
**Description**: (iOS only) Returns the native permission status of the device. Possible values include: `notDetermined`, `denied`, `authorized`, `provisional` (iOS 12+), `ephemeral` (iOS 14+).
### `var canRequest = await OneSignal.Notifications.canRequest();`
**Description**: Determines if requesting notification permission will display a prompt. Returns `true` if the user has not been prompted before.
### `OneSignal.Notifications.requestPermission(bool fallbackToSettings);`
**Description**: Prompts the user to grant push notification permission. If `fallbackToSettings` is `true`, it will direct the user to the app's settings if permission is denied.
**Example Usage**:
```dart
OneSignal.Notifications.requestPermission(true);
```
### `OneSignal.Notifications.registerForProvisionalAuthorization(bool fallbackToSettings)`
**Description**: (iOS only) Requests provisional authorization for notifications, allowing notifications to be delivered silently without an immediate user prompt. If `fallbackToSettings` is `true`, it will direct the user to the app's settings if authorization is denied.
```
--------------------------------
### Alias Management
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Manage user aliases by adding new ones, overwriting existing ones, or removing them.
```APIDOC
## OneSignal.User.addAlias
### Description
Set an alias for the current user. If this alias label already exists on this user, it will be overwritten with the new alias id.
### Method
`OneSignal.User.addAlias(String aliasLabel, String aliasId)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addAlias("custom_label", "custom_id");
```
### Response
None
## OneSignal.User.addAliases
### Description
Set aliases for the current user. If any alias already exists, it will be overwritten to the new values.
### Method
`OneSignal.User.addAliases(Map aliases)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addAliases({"label1": "id1", "label2": "id2"});
```
### Response
None
## OneSignal.User.removeAlias
### Description
Remove an alias from the current user.
### Method
`OneSignal.User.removeAlias(String aliasLabel)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.removeAlias("custom_label");
```
### Response
None
## OneSignal.User.removeAliases
### Description
Remove aliases from the current user.
### Method
`OneSignal.User.removeAliases(List aliasLabels)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.removeAliases(["label1", "label2"]);
```
### Response
None
```
--------------------------------
### Register for Provisional Authorization (iOS)
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Requests provisional authorization for push notifications on iOS, allowing notifications to be delivered silently without an immediate user prompt.
```dart
OneSignal.Notifications.registerForProvisionalAuthorization(bool fallbackToSettings)
```
--------------------------------
### Permission Observers
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add and remove listeners to observe changes in notification permission status.
```APIDOC
## Permission Observers
### `OneSignal.Notifications.addPermissionObserver(observer);`
**Description**: Adds a listener that is triggered whenever the notification permission status changes. This can occur when the user modifies settings outside the app.
**Example Usage**:
```dart
OneSignal.Notifications.addPermissionObserver((state) {
print("Has permission " + state.toString());
});
```
### `OneSignal.Notifications.removePermissionObserver(observer);`
**Description**: Removes a previously added permission observer.
```
--------------------------------
### Enter Live Activity - OneSignal Flutter
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Use this method to associate an activityId with a live activity temporary push token on OneSignal's server. This is an iOS-only feature.
```flutter
OneSignal.LiveActivities.enterLiveActivity("ACTIVITY_ID", "TOKEN");
```
--------------------------------
### Add OneSignal Flutter SDK Dependency
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Reference the OneSignal Flutter SDK using a path dependency in your pubspec.yaml file.
```yaml
onesignal_flutter:
path: ../../
```
--------------------------------
### Manage Email and SMS Subscriptions (Flutter)
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add or remove email and SMS subscriptions for a user. The remove methods are no-ops if the specified subscription does not exist.
```flutter
// Add email subscription
OneSignal.User.addEmail("customer@company.com");
// Remove previously added email subscription
OneSignal.User.removeEmail("customer@company.com");
// Add SMS subscription
OneSignal.User.addSms("+15558675309");
// Remove previously added SMS subscription
OneSignal.User.removeSms("+15558675309");
```
--------------------------------
### Email Subscription Management
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add or remove email subscriptions for the current user.
```APIDOC
## OneSignal.User.addEmail
### Description
Add a new email subscription to the current user.
### Method
`OneSignal.User.addEmail(String email)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addEmail("customer@company.com");
```
### Response
None
## OneSignal.User.removeEmail
### Description
Results in a no-op if the specified email does not exist on the user within the SDK, and no request will be made.
### Method
`OneSignal.User.removeEmail(String email)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.removeEmail("customer@company.com");
```
### Response
None
```
--------------------------------
### Login User to OneSignal
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Logs a user into OneSignal using an external ID. This switches the user context. If the external ID exists, the user is retrieved; otherwise, a new user is created. Push notification and in-app messaging subscriptions are transferred.
```dart
OneSignal.login("USER_EXTERNAL_ID");
```
--------------------------------
### Entitlements for iOS Notification Service Extension
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Configure the .entitlements file for the Notification Service Extension. The App Group specified must match the one configured in your main application's entitlements.
```xml
com.apple.security.application-groups
group.com.onesignal.example.onesignal
```
--------------------------------
### Request Location Permissions
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Manually prompt the user for location permissions to enable geotagging for location-based notifications.
```dart
OneSignal.Location.requestPermission();
```
--------------------------------
### Add Push Subscription Observer in Flutter
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Adds an observer to listen for changes in the push subscription state. The observer callback receives the current and previous states.
```dart
OneSignal.User.pushSubscription.addObserver((state) {
OSPushSubscriptionChangedState current = state.current;
OSPushSubscriptionChangedState previous = state.previous;
if (state.current.optedIn) {
/// Respond to new state
}
});
```
--------------------------------
### SMS Subscription Management
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add or remove SMS subscriptions for the current user.
```APIDOC
## OneSignal.User.addSms
### Description
Add a new SMS subscription to the current user.
### Method
`OneSignal.User.addSms(String phoneNumber)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addSms("+15558675309");
```
### Response
None
## OneSignal.User.removeSms
### Description
Results in a no-op if the specified phone number does not exist on the user within the SDK, and no request will be made.
### Method
`OneSignal.User.removeSms(String phoneNumber)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.removeSms("+15558675309");
```
### Response
None
```
--------------------------------
### Update Objective-C Import Statement
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Replace the old OneSignal import statement with the new one for Objective-C projects.
```objective-c
// Replace the old import statement
#import
// With the new import statement
#import
```
--------------------------------
### Add Tag to User
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Adds a tag to the current user. This call must be made after initialization.
```flutter
OneSignal.User.addTag("tag", "2");
```
--------------------------------
### Push Subscription Properties
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Access read-only properties of the push subscription.
```APIDOC
## Push Subscription Properties
### Description
Access read-only properties of the push subscription, including its ID, token, and opt-in status.
### Properties
#### `id`
- **Type**: `var`
- **Description**: The readonly push subscription ID.
#### `token`
- **Type**: `var`
- **Description**: The readonly push token.
#### `optedIn`
- **Type**: `var`
- **Description**: Gets a boolean value indicating whether the current user is opted in to push notifications. This returns `true` when the app has notifications permission and `optOut()` is **not** called. ***Note:*** Does not take into account the existence of the subscription ID and push token. This boolean may return `true` but push notifications may still not be received by the user.
```
--------------------------------
### NotificationService.swift for iOS
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
Implement the UNNotificationServiceExtension to process notifications before they are displayed. This Swift code handles incoming notification requests and allows for modification of notification content.
```swift
import UserNotifications
import OneSignalExtension
class NotificationService: UNNotificationServiceExtension {
var contentHandler: ((UNNotificationContent) -> Void)?
var receivedRequest: UNNotificationRequest!
var bestAttemptContent: UNMutableNotificationContent?
override func didReceive(_ request: UNNotificationRequest, withContentHandler contentHandler: @escaping (UNNotificationContent) -> Void) {
self.receivedRequest = request
self.contentHandler = contentHandler
self.bestAttemptContent = (request.content.mutableCopy() as? UNMutableNotificationContent)
if let bestAttemptContent = bestAttemptContent {
OneSignalExtension.didReceiveNotificationExtensionRequest(self.receivedRequest, with: bestAttemptContent, withContentHandler: self.contentHandler)
}
}
override func serviceExtensionTimeWillExpire() {
if let contentHandler = contentHandler, let bestAttemptContent = bestAttemptContent {
OneSignalExtension.serviceExtensionTimeWillExpireRequest(self.receivedRequest, with: self.bestAttemptContent)
contentHandler(bestAttemptContent)
}
}
}
```
--------------------------------
### OneSignal Consent Given
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Sets whether the user has given consent for their data to be sent to OneSignal.
```APIDOC
## OneSignal.consentGiven
### Description
Sets whether a user has consented to privacy prior to their user data being sent up to OneSignal.
### Method
`OneSignal.consentGiven(bool given)`
### Parameters
#### Path Parameters
- **given** (Boolean) - Required - Set to `true` if consent has been given, `false` otherwise.
```
--------------------------------
### Add User State Observer
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add a listener to observe changes in user state, such as OneSignal ID and external ID. The listener is invoked when these values change.
```dart
OneSignal.User.addObserver((state) {
var userState = state.jsonRepresentation();
print('OneSignal user changed: $userState');
});
```
--------------------------------
### Add Single User Tag
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add or update a single tag for the current user. Tags are key:value pairs used for targeting and personalization. Existing tags with the same key will be replaced.
```dart
OneSignal.User.addTag("KEY", "VALUE");
```
--------------------------------
### Session Outcome Methods
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Methods to add outcomes to the current session.
```APIDOC
## Session Outcome Methods
### Description
Methods to add outcomes with various configurations to the current session.
### Methods
#### `addOutcome(String outcomeName)`
- **Description**: Add an outcome with the provided name, captured against the current session.
#### `addUniqueOutcome(String outcomeName)`
- **Description**: Add a unique outcome with the provided name, captured against the current session.
#### `addOutcomeWithValue(String outcomeName, double value)`
- **Description**: Add an outcome with the provided name and value, captured against the current session.
```
--------------------------------
### Set OneSignal App ID in .env
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/demo-no-location/README.md
Edit the .env file to include your specific OneSignal App ID. This file must exist before the first build as Flutter bundles it as an app asset.
```sh
ONESIGNAL_APP_ID=your-onesignal-app-id
```
--------------------------------
### Add Permission Observer
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Adds a listener that is triggered when the notification permission status changes. Use `removePermissionObserver` to detach the listener.
```dart
OneSignal.Notifications.addPermissionObserver((state) {
print("Has permission " + state.toString());
});
```
```dart
/// Remove the observer
OneSignal.Notifications.removePermissionObserver(observer);
```
--------------------------------
### Tag Management
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add, remove, or retrieve tags associated with the current user. Tags are key:value pairs for targeting and personalization.
```APIDOC
## OneSignal.User.addTag
### Description
Add a tag for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.
### Method
`OneSignal.User.addTag(String key, String value)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addTag("KEY", "VALUE");
```
### Response
None
## OneSignal.User.addTags
### Description
Add multiple tags for the current user. Tags are key:value pairs used as building blocks for targeting specific users and/or personalizing messages. If the tag key already exists, it will be replaced with the value provided here.
### Method
`OneSignal.User.addTags(Map tags)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.addTags({"KEY_01": "VALUE_01", "KEY_02": "VALUE_02"});
```
### Response
None
## OneSignal.User.removeTag
### Description
Remove the data tag with the provided key from the current user.
### Method
`OneSignal.User.removeTag(String key)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.removeTag("KEY");
```
### Response
None
## OneSignal.User.removeTags
### Description
Remove multiple tags with the provided keys from the current user.
### Method
`OneSignal.User.removeTags(List keys)`
### Parameters
#### Path Parameters
None
#### Query Parameters
None
#### Request Body
None
### Request Example
```dart
OneSignal.User.removeTags(["KEY_01", "KEY_02"]);
```
### Response
None
## OneSignal.User.getTags
### Description
Returns the local tags for the current user.
### Method
`OneSignal.User.getTags()`
### Parameters
None
### Request Example
```dart
var tags = OneSignal.User.getTags();
```
### Response
- **tags** (Map) - A map containing the user's local tags.
```
--------------------------------
### Add Single User Alias
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Set a single alias for the current user. If the alias label already exists, its ID will be overwritten.
```dart
OneSignal.User.addAlias("ALIAS_LABEL", "ALIAS_ID");
```
--------------------------------
### Register OneSignal Event Observers
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build.md
Register observers for push subscription, notification permissions, and general user events. These observers allow the application to react to changes in OneSignal's state.
```dart
OneSignal.User.pushSubscription.addObserver(...)
OneSignal.Notifications.addPermissionObserver(...)
OneSignal.User.addObserver(...)
```
--------------------------------
### Delivery Progress Bar View
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/examples/build-ios.md
A SwiftUI View that displays a progress bar indicating delivery status. The bar's fill color changes to green when the status is 'delivered'.
```swift
@available(iOS 16.2, *)
struct DeliveryProgressBar: View {
let status: String
private var progress: CGFloat {
switch status {
case "on_the_way": return 0.6
case "delivered": return 1.0
default: return 0.25
}
}
var body: some View {
GeometryReader { geo in
ZStack(alignment: .leading) {
RoundedRectangle(cornerRadius: 3)
.fill(Color.white.opacity(0.2))
.frame(height: 6)
RoundedRectangle(cornerRadius: 3)
.fill(progress >= 1.0 ? Color.green : Color.blue)
.frame(width: geo.size.width * progress, height: 6)
}
}
.frame(height: 6)
}
}
```
--------------------------------
### Add Multiple Triggers for IAMs
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Add multiple triggers for the current user. If a trigger key already exists, it will be replaced. Triggers are not persisted and only exist locally for the current user.
```dart
OneSignal.InAppMessages.addTriggers({"triggerKey1":"triggerValue", "triggerKey2": "triggerValue"});
```
--------------------------------
### Add Foreground Notification Listener
Source: https://github.com/onesignal/onesignal-flutter-sdk/blob/main/MIGRATION_GUIDE.md
Adds a listener that executes before a notification is displayed while the app is in the foreground. Use `event.preventDefault()` to stop the notification from displaying and `event.notification.display()` to show it after modifications.
```dart
OneSignal.Notifications.addForegroundWillDisplayListener((event) {
/// preventDefault to not display the notification
event.preventDefault();
/// Do async work
/// notification.display() to display after preventing default
event.notification.display();
});
```
```dart
/// Remove the listener
OneSignal.Notifications.removeForegroundWillDisplayListener(listener);
```