netmera_flutter_sdk 1.0.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 74

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) {
          GeneratedPluginRegistrant.registerWith(pluginRegistry);
      }
  }
  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.0.1 #

  • Initial project release for testing.
  • Netmera Android & iOS initial integrations were completed.
  • All general event mechanisms were added.
  • Push broadcast mechanisms for Android Supported devices were integrated into dart language.

0.0.2 #

  • ReadMe was updated.

0.0.3 #

  • example/ReadMe was updated.

0.0.4 #

  • AndroidX support was added.

0.0.5 #

  • AndroidX core dependency was included and ReadMe was updated.

0.0.6 #

  • Minor bug fix for AndroidX and ReadMe was updated.

0.0.7 #

  • use_frameworks! enabled for iOS part.

0.0.8-dev #

  • NetmeraInboxCategory feature was implemented.

1.0.0 #

  • NetmeraPushInbox refactoring.
  • SendDate bug fix was implemented.
  • iOS & Android Netmera SDK upgrade.
  • HMS support for Huawei Mobile Devices.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:netmera_flutter_sdk/Netmera.dart';
import 'package:netmera_flutter_sdk/NetmeraPushBroadcastReceiver.dart';
import 'package:netmera_flutter_sdk_example/page_category.dart';

import 'page_event.dart';
import 'page_push_inbox.dart';
import 'page_settings.dart';
import 'page_user.dart';

///
/// Copyright (c) 2019 Inomera Research.
/// Author Burak Soykal
///
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,
  );
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
    Netmera.logging(true);

    Netmera.isPushEnabled().then((enabled) {
      print("Netmera: isPushEnabled = " + enabled.toString());
    });

    if (Platform.isIOS) {
      Netmera.requestPushNotificationAuthorization();
      Netmera.setAppGroupName("AppGroupName");
    }

    if (Platform.isAndroid) {
      Netmera.isWebViewProgressbarEnabled().then((enabled) {
        print("Netmera: isWebViewProgressbarEnabled = " + enabled.toString());
      });
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 5,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              tabs: [
                Tab(icon: Text("Event")),
                Tab(icon: Text("User")),
                Tab(icon: Text("PushInbox")),
                Tab(icon: Text("Settings")),
                Tab(icon: Text("Category")),
              ],
            ),
            title: Text('NM Flutter SDK'),
          ),
          body: TabBarView(
            children: [EventPage(), UserPage(), PushInboxPage(), SettingsPage(),CategoryPage()],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  netmera_flutter_sdk: ^1.0.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

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

3. Import it

Now in your Dart code, you can use:


import 'package:netmera_flutter_sdk/Netmera.dart';
import 'package:netmera_flutter_sdk/NetmeraCategory.dart';
import 'package:netmera_flutter_sdk/NetmeraCategoryFilter.dart';
import 'package:netmera_flutter_sdk/NetmeraInboxFilter.dart';
import 'package:netmera_flutter_sdk/NetmeraPushBroadcastReceiver.dart';
import 'package:netmera_flutter_sdk/NetmeraPushInbox.dart';
import 'package:netmera_flutter_sdk/NetmeraUser.dart';
import 'package:netmera_flutter_sdk/callbackDispatcher.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEvent.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventBannerOpen.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventBatteryLevel.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventCategoryView.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventInAppPurchase.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventLogin.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventRegister.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventScreenView.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventSearch.dart';
import 'package:netmera_flutter_sdk/events/NetmeraEventShare.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventCartAddProduct.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventCartRemoveProduct.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventCartView.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventOrderCancel.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventProductComment.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventProductRate.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventProductView.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventPurchase.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraEventWishList.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraLineItem.dart';
import 'package:netmera_flutter_sdk/events/commerce/NetmeraProduct.dart';
import 'package:netmera_flutter_sdk/events/media/NetmeraEventContent.dart';
import 'package:netmera_flutter_sdk/events/media/NetmeraEventContentComment.dart';
import 'package:netmera_flutter_sdk/events/media/NetmeraEventContentRate.dart';
import 'package:netmera_flutter_sdk/events/media/NetmeraEventContentView.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
47
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
74
Learn more about scoring.

We analyzed this package on Apr 7, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.7.1
  • pana: 0.13.6
  • Flutter: 1.12.13+hotfix.8

Health suggestions

Format lib/Netmera.dart.

Run flutter format to format lib/Netmera.dart.

Format lib/NetmeraCategory.dart.

Run flutter format to format lib/NetmeraCategory.dart.

Format lib/NetmeraPushInbox.dart.

Run flutter format to format lib/NetmeraPushInbox.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test