Raven Flutter SDK allows you to:

  • Manage (Create/Update) your users and their preferences on Raven.
  • Update notification statuses to Raven for push notification tracking.

Getting started

Before using the Raven SDK you need to integrate the push notification provider like Firebase and handle the rendering of notifications in your Flutter application. The steps below help you setup the SDK with Firebase. If you are using a provider other than Firebase, you can skip to the Usage section. Let’s begin by first integrating Firebase in your Flutter app.

Step 1. Setting up Firebase

Please refer to the following docs to create a Firebase project if you don’t have one and integrate your Flutter app to a new/existing Firebase project for the platforms of choice (Android, iOS, Web).

Step 2. Setting up FCM

This step shows how to handle the rendering of notifications in our Flutter app.

First follow the link: Firebase Cloud Messaging | FlutterFire and complete the necessary steps to add Firebase cloud messaging (FCM) dependency to your project.

If you are targeting iOS devices, follow the steps below to get started with APNS and add code to ask for permission to send notifications -

Step 3. Usage

Initialization

  1. Add the Raven Flutter SDK dependency in your pubspec.yaml. Please check the latest version here.
dependencies:
  raven_flutter_sdk: <latest_version>
  1. Import the SDK and call the initialize method.
import "package:raven_flutter_sdk/raven_flutter_sdk.dart";

Since the initialize method is an asynchronous operation, the main function can be modified to ensure initialization is complete before running the application.

Future<void> main() async {
    await RavenSdk.initialize(appId, apiKey);
}

The initialize method takes two parameters: the App ID & API Key which you can get from the Raven Console in the Settings tab.

Methods

  1. Set user on signup/login. You can use any of the following methods to set user. Note that this will create a user if it does not exists in Raven. If it exists, it will simply update the user if there is any change.
await RavenSdk.setUser(userID, userMobile, userEmail);
await RavenSdk.setUserEmail(userID, userEmail);
await RavenSdk.setUserMobile(userID, mobile);
All of these are asynchronous operations.
  1. Set the Firebase device token on Raven. Make sure setUser is called before setting the device token as Raven would need to associate the token with a user ID.
await RavenSdk.setDeviceToken(token);

setUser and setDeviceToken methods are required only if you want to manage users/preferences/device tokens on Raven. If you are managing the device tokens yourself, then you need not add these methods and can directly pass the device tokens in the Send Event API.

  1. Updating Notification Status.

You can update the notification statuses to Raven which you can use for tracking purposes in the logs and metrics section on Raven console. When you receive a message from Firebase in the onMessageReceived callback, you can update Raven with DELIVERED status. If you have set up Notification click and dismiss receivers, please update Raven with CLICKED and DISMISSED statuses respectively. This method takes the Raven notificationId as an argument. Raven generates a unique notification id and attaches it in the data payload.

String notificationId = message.data["raven_notification_id"];
await RavenSdk.updateStatus(notificationId, Status.DELIVERED);
await RavenSdk.updateStatus(notificationId, Status.CLICKED);
await RavenSdk.updateStatus(notificationId, Status.DISMISSED);
  1. When the user logs out of your app, we need to de-register the device token. Call logout to logout the user from Raven.
await RavenSdk.logout();

Step 4. Test

Once you are done with the setup, you can follow the steps below to test -

  1. Make sure Firebase is able to generate the device token in your app. Next, if you had set the user and device token on Raven, you should start seeing them in the Users tab on the Raven console.
  2. Add Firebase Integration on Raven.
  3. Create an event with Push as a channel on the Raven console.
  4. As a final step, either you can send a test notification directly from Raven console or use the Raven SDK to send a test notification.
    • Sending via console - In the Event list, you will see the Event that you created in the previous step. Click the Send Event button. In the recipient details, you can either pass the device token directly or pass user_id if you had set the user on Raven. Click on send.
    • Sending via the SDK - The SDK has a method to send notification: sendMessage(<event_name>, <user_id>). You can pass the event name that you created in the previous step and the user id of the user that was set during login/signup.

If you were able to successfully receive the push notification, you are all set! 👍

If you are facing any issues, please email us on support@ravenapp.dev

Demo

Our Flutter demo app shows this integration in detail. Please check the Demo App.

  1. Firebase Flutter Notifications
  2. Flutter Official Example Repo