Flutter SDK Basic integration guide
This section contains information on how to integrate the Pushwoosh Flutter SDK into your application.
Prerequisites
Section titled “Prerequisites”To integrate the Pushwoosh Flutter SDK into your app, you will need the following:
Integration steps
Section titled “Integration steps”1. Add Pushwoosh Flutter SDK Dependency
Section titled “1. Add Pushwoosh Flutter SDK Dependency”Add the pushwoosh_flutter
package to your pubspec.yaml
file:
dependencies: flutter: sdk: flutter # Use the latest version from https://pub.dev/packages/pushwoosh_flutter pushwoosh_flutter: ^[LATEST_VERSION]
Check the latest version on pub.dev.
Then, run the following command in your project’s root directory to install the dependency:
flutter pub get
Double check that the package is installed correctly:
flutter pub deps | grep pushwoosh_flutter
# Example output:# ❯ flutter pub deps | grep pushwoosh_flutter# └── pushwoosh_flutter 2.3.11
2. Flutter SDK Initialization
Section titled “2. Flutter SDK Initialization”In the root component of your main.dart
file:
- Import the
pushwoosh_flutter
package. - Initialize the Pushwoosh SDK.
- Call
registerForPushNotifications()
in your initialization logic to register for push notifications.
import 'package:pushwoosh_flutter/pushwoosh_flutter.dart';
void main() async { runApp(const MyApp()); Pushwoosh.initialize({ "app_id": "__YOUR_APP_ID__", "sender_id": "__YOUR_FCM_SENDER_ID__" }); Pushwoosh.getInstance.registerForPushNotifications();}
Where:
__YOUR_APP_ID__
is the application code from the Pushwoosh Control Panel.__YOUR_FCM_SENDER_ID__
is the Firebase project number from the Firebase Console.
3. iOS Native Setup
Section titled “3. iOS Native Setup”3.1 Install dependencies
Section titled “3.1 Install dependencies”Navigate to the ios directory and install the dependencies:
cd ios && pod install --repo-update
3.2 Capabilities
Section titled “3.2 Capabilities”To enable Push Notifications in your project, you need to add certain capabilities.
In the Signing & Capabilities section, add the following capabilities:
Push Notifications
Background Modes
. After adding this capability, check the box forRemote notifications
.
If you intend to use Time Sensitive Notifications (iOS 15+), also add the Time Sensitive Notifications
capability.
3.3 Info.plist
Section titled “3.3 Info.plist”In your Runner/Info.plist
set the __PUSHWOOSH_DEVICE_API_TOKEN__
key to the device API Token:
<key>Pushwoosh_API_TOKEN</key><string>__PUSHWOOSH_DEVICE_API_TOKEN__</string>
3.4 Message delivery tracking
Section titled “3.4 Message delivery tracking”You must add a Notification Service Extension target to your project. This is essential for accurate delivery tracking and features like Rich Media on iOS.
Follow the native guide’s steps to add the extension target and the necessary Pushwoosh code within it.
4. Android Native Setup
Section titled “4. Android Native Setup”4.1 Install dependencies
Section titled “4.1 Install dependencies”Ensure that the required dependencies and plugins are added to your Gradle scripts:
Add the Google Services Gradle plugin to your project-level build.gradle
dependencies:
dependencies { classpath 'com.google.gms:google-services:4.3.15'}
Apply the plugin in your app-level build.gradle
file:
apply plugin: 'com.google.gms.google-services'
4.2 Add Firebase configuration file
Section titled “4.2 Add Firebase configuration file”Place the google-services.json
file into android/app
folder in your project directory.
4.3 Add Pushwoosh metadata
Section titled “4.3 Add Pushwoosh metadata”In your main/AndroidManifest.xml
add Pushwoosh Device API Token inside the <application>
tag:
<meta-data android:name="com.pushwoosh.apitoken" android:value="__YOUR_DEVICE_API_TOKEN__" />
Important: Be sure to give the token access to the right app in your Pushwoosh Control Panel. Learn more
5. Run the Project
Section titled “5. Run the Project”- Build and run the project.
- Go to the Pushwoosh Control Panel and send a push notification.
- You should see the notification in the app.
Using ProGuard
Section titled “Using ProGuard”Thus, you may get this exception:
java.lang.IllegalStateException: Could not find class for name: com.pushwoosh.plugin.PushwooshNotificationServiceExtension
There are two solutions in this case:
- Use the
flutter build apk --no-shrink
command to compile your code without obfuscation. - Or you can manually enable ProGuard and add the necessary rules.
To enable ProGuard for your project, add the following strings to your build.gradle
file:
buildTypes { release { minifyEnabled true useProguard true proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
signingConfig signingConfigs.debug } }
Then, add the following rules to the android/app/proguard-rules.pro
#Pushwoosh Flutter-keep class com.pushwoosh.plugin.PushwooshPlugin { *; }-keep class com.pushwoosh.plugin.PushwooshNotificationServiceExtension { *; }
Troubleshooting
Section titled “Troubleshooting”If you encounter any issues during the integration process, please refer to the support and community section.