This Tutorial aims to teach the user how to integrate his Cross Platform Flutter Flutter app with cloud using SDK and how to use the products

To integrate the Appgain SDK in your flutter app, you have to use pub dev

How To Upgrade it ?

  • update plugin version from pubspec.yaml and of Plugin For example : update version 0.0.2 to be 0.0.3

  • run the publish command in dry-run mode to see if everything passes analysis:

flutter pub publish --dry-run

The next step is publishing to, but be sure that you are ready because publishing is forever:

flutter pub publish

Required For Setup


Run this command: With Flutter:

$ flutter pub add appgain_sdk

This will add a line like this to your package's pubspec.yaml (and run an implicit flutter pub get):

  appgain_sdk: ^0.0.3

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

Import it

Now in your Dart code, you can use:

import 'package:appgain_sdk/appgain_sdk.dart';


  • add those lines into your App Entry Point to initialize Appgain SDK
///required appId => String 
///required apiKey => String
Appgain().initAppgainSDK(appId : 'YOUR APP ID',apiKey:'YOUR API KEY'); 


  • add those lines into your App Entry Point to initialize Appgain SDK
///required appId => String 
///required apiKey => String
Appgain().initAppgainSDK(appId : 'YOUR APP ID',apiKey:'YOUR API KEY'); 

Deferred Deep Linking

After a new user has installed your app, our SDK will detect if the app was installed from a smart
deep link or not, if it's then our SDK will automatically route their flow to marketing campaign
desired location in the app (not just to the default home screen).

To achieve that, SDK must be installed in the app, and the matching process must be


The following data are returned on matching success :

|Returned Field|Description|
| smart_link_url | the URL of smart deep link used to open or install the App |
| smart_link_id | the Id of smart deep link used to open or install the App |
| smart_link_name | the Id of smart deep link used to open or install the App |
| match_type | how the device identification done , it could be basic(Digital fingerprinting) or advertising_id |
| extra_data | array of more data |
| extra_data.userId | user Id that was appended to smart link url on opening it phase |
| params | array of all paramaters appended to smart link url , like SDL URL?utm_source=fb |
| smart_link_primary | primary redirection action |

You can return data by this code If you send params in your match deep link for example => you can get coupon from params

Appgain().matchLink().then((result) {
      if (result != null) {

For fire automator

without Personalization

// required triggerPointName  
await Appgain().fireAutomator(triggerPoint: 'YOUR TRIGGER POINT NAME');

with Personalization

  • If you need personalization add data in map
  • you can add your key and value that you want {key : value}
// required triggerPoint  
var personalizationData = {
		'name': 'Jone',
		'cartName': 'Sports' ,
		'key', 'value'}; 
await Appgain().fireAutomatorWithPersonalization(
			triggerPoint: 'YOUR TRIGGER POINT NAME'  ,  
			personalizationMap: personalizationData);  

Revenue Tracking

you can add new Purchase Transactions object by using the following snippet :

/// required productName => String 
/// required amount => double 
/// required currency => String  
await Appgain().addPurchase(  
		productName: 'productName',  
		amount: 100,
		currency: 'USD');

App Events Logging

at your app whenever you want to log AppEvent, add the following snippet :

// required type 
// optional action  
// optional extras map  
await Appgain().logEvent( 
		type: 'google',  
		extras: {  
			'YOUR KEY 1': 'YOUR VALUE 1',  
			'YOUR KEY 2': 'YOUR VALUE 2',},  
		action: 'registeration');   

Add Custom User Property

at your app whenever you want to Add Custom User Property , add the following snippet :

var updatedData = {  
	'userEmail': 'userEmail',  
	'phone': 'phone',  
	'updatedField1': 'value',  
	'updatedField2': 'value'};  
await Appgain().updateUser(data: updatedData);  

Getting Appgain user Id

// Getting userID  
// Output  : - callback with userID  

Notification Channels

This Tutorial aims to teach the user how to add user Notification and messaging preferences in
channels such as SMS and Email

 //MARK: enableReceiveNotification 
 //type (String) one of theses values ("appPush","sms","email") 
 await Appgain().enableReciveNotification(type: 'Notification Type'); 

Android Specific Instructions

  • In Project-level build.gradle (

    • in section allproject --> repositories --> add
      maven { url "" } 
    • in section dependencies add --> add
  • App-level build.gradle (project/app/build.gradle):

    dependencies {  
        implementation platform('')  
        annotationProcessor 'android.arch.lifecycle:compiler:1.1.1'  
        implementation "androidx.lifecycle:lifecycle-runtime:2.2.0"  
        implementation "androidx.lifecycle:lifecycle-process:2.2.0"  
        implementation 'io.appgain.sdk:appgain-android:4.1.26'  
        implementation ''  
  • and in the end of your file add the following line

    apply plugin: '' 
  • in defaultConfig Section add

     minSdkVersion 19 
  • go to and log in with a Google Account.

  • At Firebase Website, in the right corner click on GO TO CONSOLE and click on Add Project , then
    give your Project a name.

  • Click on the settings icon next to Project Overview and then click on Project Settings

  • Click on GENERAL > Add Firebase to your Android app icon then fill in fields with :

  • Android package name : you can find it's value inside application Id value in app/build.gradle

  • Debug signing certificate SHA- 1 ,you can get it from :

  • Android studio > Gradle menu in (right toolbar of android studio)

  • Click on app menu

  • Click on android menu

  • Click on android on signingReport task

  • Get SHA1 from run menu

  • Return to Firebase console click on REGISTER APP.

  • Download google-services.json file.

  • Add google-services.json file to app folder in your android project files

  • Follow Firebase instructions.

Push Notification setup

  • Open Firebase console, Go to project settings.

    enter image description here

  • Go to Cloud Messaging tab and copy SenderID and Legacy server key.

    enter image description here

  • Open Appgain Dashboard

  • Go to Project Setting > Advanced Setting > Platforms

  • Navigate to Android push tab

  • enter your SenderID and Server key

    enter image description here

  • if you are using proguard add this proguard rule to your , add

     keep class io.appgain.sdk.** {*;}  
  • Create a new class that extends from AppgainPushReceiver class

Class Name => PushReceiver

import android.content.Context;
import android.content.Intent;  
import android.util.Log;  
import android.widget.Toast;  
import androidx.annotation.NonNull;  
import io.appgain.sdk.controller.AppgainPushReceiver;  
import io.appgain.sdk.model.push.ReceiveStatus;  
public class PushReceiver extends AppgainPushReceiver {  
	 @Override protected void onReceive(Context context, ReceiveStatus receiveStatus, Intent intent) {  
	 Log.e("appgain", "test notificain");  
  • In your android application class, implement LifecycleObserver interface and add the following

Class Name => AppController

package com.example.appgain_io_example;  
import android.content.Context;  
import androidx.lifecycle.Lifecycle;  
import androidx.lifecycle.LifecycleObserver;  
import androidx.lifecycle.OnLifecycleEvent;  
import androidx.lifecycle.ProcessLifecycleOwner;  
import androidx.multidex.MultiDex;  
import androidx.multidex.MultiDexApplication;  
import io.appgain.sdk.controller.Appgain;  
import io.appgain.sdk.model.User;  
import io.appgain.sdk.util.Config;  
 * Created by on 12/28/2021. */  
public class AppController extends MultiDexApplication implements LifecycleObserver {  
  public static final boolean DEBUG_MODE =false;  
    private static AppController mInstance;  
    String TAG = "AppController";  
    public static boolean DIALOG_CANCELLABLE = true;  
    public void onCreate() {  
        mInstance = this;  
  void onAppBackgrounded() {  
  void onAppForegrounded() {  
    protected void attachBaseContext(Context base) {  
  public static synchronized AppController getInstance() {  
  return mInstance;  
  • Open manifest.xml file and add the following lines:
    • In "-application-" section add this line
    • also add
			 <action android:name="com.parse.push.intent.RECEIVE" />  
			 <action android:name="com.parse.push.intent.DELETE" />  
			 <action android:name="com.parse.push.intent.OPEN" />  
	<service android:name="io.appgain.sdk.controller.AppgainMessagingService">  
			 <action android:name="" />  

iOS Specific Instructions


1- Add appgain pod to your generated project from flutter.

pod 'Appgain'

2- Copy this file to your project from demo app.


3- How we start with this code

  • Inside AppDelegate.swift
@objc class AppDelegate: FlutterAppDelegate {
  override func application(
    _ application: UIApplication,
    didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]?
  ) -> Bool {
    GeneratedPluginRegistrant.register(with: self)
    return super.application(application, didFinishLaunchingWithOptions: launchOptions)

Add Notification to your iOS target

Push Notification Setup

Add Appgain Rich Notification

Guide for native Rich Notification 1- Add target for rich notification 2- Add pod of rich push for two target

pod 'Appgain-Rich'

For more info about all the methods in the Appgain SDK. please, refer to our native guides for ios Finally You Can Use Appgain SDKTestApp to Test Appgain Features Before Integrate Your App with Appgain