netmera_flutter_sdk 1.0.4

Flutter Android iOS

NETMERA is a Mobile Application Engagement Platform. We offer a series of development tools and app communication features to help your mobile business ignite and soar.

Netmera Flutter SDK #

NETMERA is a Mobile Application Engagement Platform. We offer a series of development tools and app communication features to help your mobile business ignite and soar.

Installation #

For using this package as a library:
  • Add this to your package's pubspec.yaml file
dependencies:
  netmera_flutter_sdk: ^x.x.x
  • You can install packages from the command line with Flutter:
$ flutter pub get

For both native sides(Android & iOS) you don't have to include extra Netmera SDK libraries.

Setup - Android Part #

  1. Create and register your app in Firebase console.

  2. Download google-services.json file and place it into android/app/ folder.

  3. In your project's build gradle file, add the following dependency.

buildscript {
    repositories {
        google()
        jcenter()
        maven {url 'http://developer.huawei.com/repo/'}
    }

    dependencies {
        classpath 'com.android.tools.build:gradle:3.5.3'
        classpath 'com.google.gms:google-services:4.3.1'
        classpath 'com.huawei.agconnect:agcp:1.2.0.300'
    }
}

allprojects {
    repositories {
        google()
        jcenter()
        maven { url 'https://maven.google.com'}
        maven {url 'http://developer.huawei.com/repo/'}
    }
}
  1. In your app's build gradle file, add the following dependency.

 dependencies {
 
     implementation 'androidx.core:core:1.1.0'
     
 }
  1. Add the following into the bottom of app's buid.gradle file
apply plugin: 'com.google.gms.google-services'
  1. Create an application class as shown below.
  • Your Application class must extends FlutterApplication and implements PluginRegistry.PluginRegistrantCallback , if you want to listen Push Broadcasts in dart part.
public class NMApp extends FlutterApplication implements PluginRegistry.PluginRegistrantCallback {

      @Override
      public void onCreate() {

          super.onCreate();

          FNetmeraService.setPluginRegistrant(this); // This is needed for receiving push broadcasts in dart classes
          FNetmera.logging(true); // This is for enabling Netmera logs.
          FNetmera.init(this, <YOUR GCM SENDER ID>, <YOUR NETMERA API KEY>); // Calling Netmera init.
      }

      @Override
      public void registerWith(PluginRegistry pluginRegistry) { }
  }
  1. Override configureFlutterEngine method on your Activity class as below.
public class MainActivity extends FlutterActivity {

    @Override
    public void configureFlutterEngine(@NonNull FlutterEngine flutterEngine) {
        GeneratedPluginRegistrant.registerWith(flutterEngine);
    }
}
  1. Register Application and Service classes into manifest file.
 <application
        android:name=".NMApp"
        android:label="netmera_flutter_sdk_example"
        android:icon="@mipmap/ic_launcher">

        <!-- Register broadcast class as below -->
        <receiver
            android:name="com.netmera.netmera_flutter_sdk.FNetmeraPushBroadcastReceiver"
            android:enabled="true"
            android:exported="true">
            <intent-filter>
                <action android:name="com.netmera.push.intent.REGISTER" />
                <action android:name="com.netmera.push.intent.RECEIVE" />
                <action android:name="com.netmera.push.intent.OPEN" />
                <action android:name="com.netmera.push.intent.DISMISS" />
                <action android:name="com.netmera.push.intent.BUTTON" />
            </intent-filter>
        </receiver>

         <!-- Register service class as below -->
        <service
            android:name="com.netmera.netmera_flutter_sdk.FNetmeraService"
            android:exported="true"
            android:permission="android.permission.BIND_JOB_SERVICE">
            <intent-filter>
                <action android:name="android.intent.action.BOOT_COMPLETED" />
                <action android:name="android.intent.action.QUICKBOOT_POWERON" />
            </intent-filter>
        </service>

        ...
        ..
        .
  1. Inside dart class add the following
void main() {
  initBroadcastReceiver();
  runApp(MyApp());
}

void _onPushRegister(Map<dynamic, dynamic> bundle) async {
  print("onPushRegister: $bundle");
}

void _onPushReceive(Map<dynamic, dynamic> bundle) async {
  print("onPushReceive: $bundle");
}

void _onPushDismiss(Map<dynamic, dynamic> bundle) async {
  print("onPushDismiss: $bundle");
}

void _onPushOpen(Map<dynamic, dynamic> bundle) async {
  print("onPushOpen: $bundle");
}

void _onPushButtonClicked(Map<dynamic, dynamic> bundle) async {
  print("onPushButtonClicked: $bundle");
}

void initBroadcastReceiver() {
  NetmeraPushBroadcastReceiver receiver = new NetmeraPushBroadcastReceiver();
  receiver.initialize(
    onPushRegister: _onPushRegister,
    onPushReceive: _onPushReceive,
    onPushDismiss: _onPushDismiss,
    onPushOpen: _onPushOpen,
    onPushButtonClicked: _onPushButtonClicked,
  );
}

Setup - iOS Part #

  1. Navigate to ios folder in your terminal and run the following command.
$ pod install
  1. If you are using Swift, enter the following in your Runner-Bridging-Header.h.
#import "FNetmera.h"
#import "FNetmeraService.h"
#import "NetmeraFlutterSdkPlugin.h"
  1. If you want to use Android alike message sending from iOS to dart please consider to shape your AppDelegate class as following.
import UIKit
import Flutter

//This function is needed for sending messages to the dart side. (Setting the callback function)
func registerPlugins(registry: FlutterPluginRegistry) {
    GeneratedPluginRegistrant.register(with: registry)
};

@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate,UNUserNotificationCenterDelegate,NetmeraPushDelegate {

    override func application(_ application: UIApplication,
                didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool {
    GeneratedPluginRegistrant.register(with: self)

        if #available(iOS 10.0, *) {
        UNUserNotificationCenter.current().delegate = self
    } else {
        // Fallback on earlier versions
    };

        //For triggering onPushReceive when app is killed and push clicked by user
        let notification = launchOptions?[.remoteNotification]
        if notification != nil {
            self.application(application, didReceiveRemoteNotification: notification as! [AnyHashable : Any])
        }

    //This function is needed for sending messages to the dart side.
    NetmeraFlutterSdkPlugin.setPluginRegistrantCallback(registerPlugins)

    FNetmera.logging(true) // Enable Netmera logging
    FNetmera.init("<YOUR-NETMERA-KEY>") //Initializing Netmera packages.
    FNetmera.setPushDelegate(self) //

    return super.application(application, didFinishLaunchingWithOptions: launchOptions)
  }


    override func application(_ application: UIApplication, didRegisterForRemoteNotificationsWithDeviceToken deviceToken: Data) {
        FNetmeraService.handleWork(ON_PUSH_REGISTER, dict: ["pushToken": deviceToken])
    }

    override func application(_ application: UIApplication, didReceiveRemoteNotification userInfo: [AnyHashable : Any]) {
        FNetmeraService.handleWork(ON_PUSH_RECEIVE, dict:["userInfo" : userInfo])
    }


    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter,
                                didReceive response: UNNotificationResponse,
                                withCompletionHandler completionHandler:
        @escaping () -> Void) {

        if response.actionIdentifier == UNNotificationDismissActionIdentifier {
            FNetmeraService.handleWork(ON_PUSH_DISMISS,dict:["userInfo" : response.notification.request.content.userInfo])
        }
        else if response.actionIdentifier == UNNotificationDefaultActionIdentifier {
            FNetmeraService.handleWork(ON_PUSH_OPEN, dict:["userInfo" : response.notification.request.content.userInfo])
        }
        completionHandler()
    }

    @available(iOS 10.0, *)
    func userNotificationCenter(_ center: UNUserNotificationCenter, willPresent notification: UNNotification, withCompletionHandler completionHandler: @escaping (UNNotificationPresentationOptions) -> Void) {
        completionHandler([UNNotificationPresentationOptions.alert])
    }
}

For example if you trigger FNetmeraService.handleWork(ON_PUSH_RECEIVE, dict:["userInfo" : userInfo]) from AppDelegate, in the dart part the following method will be triggered.

void _onPushReceive(Map<dynamic, dynamic> bundle) async {
  print("onPushReceive: $bundle");
}

Please take a look at Setup-Android part 8

Calling Dart methods #

Update User Example
updateUser() {
    NetmeraUser user = new NetmeraUser();
    user.setUserId(userController.text);
    user.setName(nameController.text);
    user.setSurname(surnameController.text);
    user.setEmail(emailController.text);
    user.setMsisdn(msisdnController.text);
    user.setGender(int.parse(_selectedGender));
    Netmera.updateUser(user);
  }
Sending Event Examples
  void sendLoginEvent() {
    NetmeraEventLogin loginEvent = new NetmeraEventLogin();
    Netmera.sendEvent(loginEvent);
  }

  void sendRegisterEvent() {
    NetmeraEventRegister registerEvent = new NetmeraEventRegister();
    Netmera.sendEvent(registerEvent);
  }

  void sendViewCartEvent() {
    NetmeraEventCartView cartViewEvent = new NetmeraEventCartView();
    cartViewEvent.setItemCount(3);
    cartViewEvent.setSubTotal(15.99);
    Netmera.sendEvent(cartViewEvent);
  }

  void purchaseEvent() {
    NetmeraLineItem netmeraLineItem = new NetmeraLineItem();
    netmeraLineItem.setBrandId("brandId12");
    netmeraLineItem.setBrandName("brandNameInomera");
    netmeraLineItem.setCampaignId("campaignId1223");
    netmeraLineItem.setCategoryIds(["categoryIds1", "categoryIds2"]);
    netmeraLineItem.setCategoryNames(["categoryNames1", "categoryNames2", "categoryNames3"]);
    netmeraLineItem.setKeywords(["keyword1", "keyword2", "keyword3"]);
    netmeraLineItem.setCount(12);
    netmeraLineItem.setId("Id123123");
    netmeraLineItem.setPrice(130);

    NetmeraEventPurchase purchaseEvent = new NetmeraEventPurchase();
    purchaseEvent.setCoupon("INOMERACODE");
    purchaseEvent.setDiscount(10);
    purchaseEvent.setItemCount(2);
    purchaseEvent.setPaymentMethod("Credit Card");
    purchaseEvent.setSubTotal(260.89);
    purchaseEvent.setShippingCost(0.0);
    purchaseEvent.setLineItems([netmeraLineItem, netmeraLineItem]);
    Netmera.sendEvent(purchaseEvent);
  }
Netmera Inbox Examples
 String _currentStatus = Netmera.PUSH_OBJECT_STATUS_ALL.toString();
 String _count = "0";
 List<Widget> _inbox = List();
 List<NetmeraPushInbox> _pushInboxList = List();

 fillInboxList(list) {
    _pushInboxList = list;
    list.forEach((NetmeraPushInbox item) {
      setState(() {
        _inbox.add(Text(item.getTitle() == null? "No title": item.getTitle() + " (" + getStatusText(item.getInboxStatus()) + ")"));
      });
    });
 }
 
 getInboxFilter() {
    NetmeraInboxFilter inboxFilter = new NetmeraInboxFilter();
    inboxFilter.setPageSize(2);
    inboxFilter.setStatus(int.parse(_currentStatus));
    inboxFilter.setIncludeExpiredObjects(true);
    inboxFilter.setCategories(null);
    return inboxFilter;
  }

 fetchInbox() async {
    clearInboxList();
    Netmera.fetchInbox(getInboxFilter()).then((list) {
      fillInboxList(list);
    });
 }

 fetchNextPage() async {
   Netmera.fetchNextPage().then((list) {
     if (list.isNotEmpty) {
       clearInboxList();
     }
     
     fillInboxList(list);
    });
  }
  
  countForStatus() async {
    Netmera.countForStatus(int.parse(_currentStatus)).then((val) {
      setState(() {
        if (val != -1) {
          _count = val.toString();
        }
      });
    });
  }

  handlePushObject() async {
    if(_pushInboxList.isNotEmpty) {
      Netmera.handlePushObject(_pushInboxList[0].getPushId());
    }
  }

  inboxUpdateStatus() {
    List<String> selectedPushList = List();

    if (_pushInboxList.length > 1) {
      selectedPushList.add(_pushInboxList[0].getPushId());
      selectedPushList.add(_pushInboxList[1].getPushId());
    }

    int status = Netmera.PUSH_OBJECT_STATUS_UNREAD;
    Netmera.inboxUpdateStatus(selectedPushList, status);
  }
  
  clearInboxList() {
    setState(() {
      _inbox.clear();
    });
  }
 
Netmera Inbox Category Examples
 String _currentStatus = Netmera.PUSH_OBJECT_STATUS_ALL.toString();
 List<Widget> _categories = List();
 List<NetmeraCategory> _categoryList = List();
  
 fillCategoryList(list) {
    _categoryList = list;
    list.forEach((NetmeraCategory item) {
      setState(() {
        _categories.add(Text(item.getCategoryName() +" :: (Read:" + item.getReadCount().toString() + ")-(UnRead:" + item.getUnReadCount().toString() + ")-(Deleted:" + item.getDeletedCount().toString() + ")"));
      });
    });
 }
  
 getCategoryFilter() {
    NetmeraCategoryFilter categoryFilter = new NetmeraCategoryFilter();
    categoryFilter.setPageSize(2);
    categoryFilter.setStatus(int.parse(_currentStatus));
    categoryFilter.setIncludeExpiredObjects(true);
    return categoryFilter;
  }
  
  fetchCategory() async {
    clearCategoryList();
    Netmera.fetchCategory(getCategoryFilter()).then((list) {
      fillCategoryList(list);
    });
  }

  fetchNextCategoryPage() async {
    Netmera.fetchNextCategory().then((list) {
      if (list.isNotEmpty) {
        clearCategoryList();
      }
      fillCategoryList(list);
    });
  }

  handlePushObject() async {
    if(_categoryList.isNotEmpty) {
      Netmera.handleLastMessage(_categoryList[0]);
    }
  }

For detailed information please explore example folder in the Netmera sdk library.

0
likes
90
pub points
56%
popularity

NETMERA is a Mobile Application Engagement Platform. We offer a series of development tools and app communication features to help your mobile business ignite and soar.

Homepage

Documentation

API reference

Uploader

soykalburak@gmail.com

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on netmera_flutter_sdk