Flutter
How to integrate Pushwoosh SDK into your Flutter project

Supports iOS, Android

Note:

iOS Simulator can neither subscribe to nor receive push notifications. Android Emulator works fine though.
If you encounter errors when migrating Pushwoosh Flutter Plugin to version 2.1.0 or higher, please refer to the guide on fixing known issues for solutions.

Prerequisites

1. Create an app on Firebase Cloud Messaging Console. You may use this guide for reference (section Manually add Firebase).
2. Get iOS push certificates by following the iOS Platform Configuration guide.
3. Configure the App in Pushwoosh Control Panel. Please follow Android configuration guide for Andriod and iOS Platform Configuration guide for iOS.

Enable push notifications in your project

First, you need to add the pushwoosh package to your project:
1. Add a dependency to your pubspec.yaml file:
1
dependencies:
2
pushwoosh: ^1.8.0
Copied!
2. Install the package from the command line:
1
$ flutter packages get
Copied!
3. Import the package in your dart code
1
import 'package:pushwoosh/pushwoosh.dart';
Copied!
Second, place the google-services.json file into android/app folder in your project directory.

google-services.json

You should've gotten the google-services.json file while creating the app in Firebase console. If you haven't, please consult this thread (section Get a config file for your Android app).
Third, initialize the plugin:
1
Pushwoosh.initialize({"app_id": "YOUR_APP_ID", "sender_id": "FCM_SENDER_ID"});
Copied!
To register for push notifications, call the following method:
1
Pushwoosh.getInstance.registerForPushNotifications();
Copied!
To process various events, use the corresponding listeners as follows. Push receipt:
1
Pushwoosh.getInstance.onPushReceived.listen((event) {
2
...
3
});
Copied!
Push open:
1
Pushwoosh.getInstance.onPushAccepted.listen((event) {
2
...
3
});
Copied!
Deep Link open:
1
Pushwoosh.getInstance.onDeepLinkOpened.listen((link) {
2
...
3
});
Copied!
All done!

Plugin API

To find more details on using the plugin, please see Plugin API Docs.

Using ProGuard

Note that the flutter build apk command obfuscates your code by default.
Thus, you may get this exception:
1
java.lang.IllegalStateException: Could not find class for name: com.pushwoosh.plugin.PushwooshNotificationServiceExtension
Copied!
There are two solutions in this case:
    1.
    Use the flutter build apk --no-shrink command to compile your code without obfuscation.
    2.
    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:
build.gradle
1
buildTypes {
2
release {
3
minifyEnabled true
4
useProguard true
5
proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
6
7
signingConfig signingConfigs.debug
8
}
9
}
Copied!
Then, add the following rules to the android/app/proguard-rules.pro
proguard-rules.pro
1
#Pushwoosh Flutter
2
-keep class com.pushwoosh.plugin.PushwooshPlugin { *; }
3
-keep class com.pushwoosh.plugin.PushwooshNotificationServiceExtension { *; }
Copied!
Last modified 25d ago
Copy link