Skip to content

Flutter

Plugin source
Sample
Plugin API Docs
Message Inbox Plugin API Docs

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:

dependencies:
pushwoosh_flutter: ^2.2.14

2. Install the package from the command line:

$ flutter packages get

3. Import the package in your dart code:

import 'package:pushwoosh_flutter/pushwoosh_flutter.dart';

Second, place the google-services.json file into android/app folder in your project directory.

Third, initialize the plugin:

Pushwoosh.initialize({"app_id": "YOUR_APP_ID", "sender_id": "FCM_SENDER_ID"});

To register for push notifications, call the following method:

Pushwoosh.getInstance.registerForPushNotifications();

If you encounter the following exception after integrating Pushwoosh in a Flutter application:

FCM registration error: Failed to retrieve token. Is firebase configured correctly?
  1. Ensure that the required dependencies and plugins are added to your Gradle scripts. Follow the steps below:

Add the following classpath to your android/build.gradle dependencies:

classpath 'com.google.gms:google-services:4.3.14'

Apply the plugin in your android/app/build.gradle file:

apply plugin: 'com.google.gms.google-services'
  1. Ensure that the parameters passed to Pushwoosh.initialize() are correctly configured.

To process various events, use the corresponding listeners as follows.

Push receipt:

Pushwoosh.getInstance.onPushReceived.listen((event) {
...
});

Push open:

Pushwoosh.getInstance.onPushAccepted.listen((event) {
...
});

Deep Link open:

Pushwoosh.getInstance.onDeepLinkOpened.listen((link) {
...
});

All done!

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:

  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
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

proguard-rules.pro
#Pushwoosh Flutter
-keep class com.pushwoosh.plugin.PushwooshPlugin { *; }
-keep class com.pushwoosh.plugin.PushwooshNotificationServiceExtension { *; }

Share your feedback with us

Your feedback helps us create a better experience, so we would love to hear from you if you have any issues during the SDK integration process. If you face any difficulties, please do not hesitate to share your thoughts with us via this form.