sdxfluttersdk 0.0.1
sdxfluttersdk: ^0.0.1 copied to clipboard
Brands use a wide range of offline and online communication touch points with multiple identities across them.
example/lib/main.dart
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:sdxfluttersdk/sdxfluttersdk.dart';
import 'dart:convert';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/foundation.dart';
void main() async {
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS) {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
}
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
title: 'SdxFlutterSDK-Example',
theme: ThemeData(
// This is the theme of your application.
//
// Try running your application with "flutter run". You'll see the
// application has a blue toolbar. Then, without quitting the app, try
// changing the primarySwatch below to Colors.green and then invoke
// "hot reload" (press "r" in the console where you ran "flutter run",
// or simply save your changes to "hot reload" in a Flutter IDE).
// Notice that the counter didn't reset back to zero; the application
// is not restarted.
primarySwatch: Colors.blue,
),
home: const MyHomePage(title: 'Flutter Demo'),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
// This widget is the home page of your application. It is stateful, meaning
// that it has a State object (defined below) that contains fields that affect
// how it looks.
// This class is the configuration for the state. It holds the values (in this
// case the title) provided by the parent (in this case the App widget) and
// used by the build method of the State. Fields in a Widget subclass are
// always marked "final".
final String title;
@override
State<MyHomePage> createState() => _MyHomePageState();
}
final _sdxfluttersdk = Sdxfluttersdk();
final _reflutterSdk = _sdxfluttersdk;
method() async {
_reflutterSdk.unReadNotification("CampaignId");
}
class _MyHomePageState extends State<MyHomePage> {
//
// late FirebaseMessaging messaging;
late var screenName;
late var receivedData;
var token;
StreamSubscription<String>? streamSubscription;
@override
void initState() {
super.initState();
if (kIsWeb) {
_sdxfluttersdk.initWebSDK("./sw.js");
}
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS) {
_getFcmToken();
}
if(defaultTargetPlatform == TargetPlatform.android){
deeplinkListener();
}else{
getDeeplinkData();
}
}
deeplinkListener() {
/*
* Listen to deeplink data
*/
streamSubscription =
_sdxfluttersdk.listenDeeplinkData().listen((data) async {
try {
debugPrint('DeepLink Listener :: $data');
var deeplinkData = jsonDecode(data);
var customParams = deeplinkData['customParams'];
///to reset deeplink data
_sdxfluttersdk.deepLinkDataReset();
if (customParams != null) {
screenNavigator(jsonDecode(customParams)['screenName'],
jsonDecode(customParams)['data']);
}
} catch (e) {
debugPrint('$e');
}
});
}
screenNavigator(var screenName, var data) {
switch (screenName) {
case "CareerPage":
{
if (data != null) {
///To pass data while navigating
}
else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Page1()),
);
}
break;
}
case "CertificationPage":
{
if (data != null) {
///To pass data while navigating
}
else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Page2()));
}
break;
}
case "Page3":
{
if (data != null) {
///To pass data while navigating
}
else {
Navigator.push(
context,
MaterialPageRoute(builder: (context) => const Page3()));
}
break;
}
default:
{
debugPrint("ScreenName is not defined!!!");
}
}
}
getDeeplinkData() {
_sdxfluttersdk.listener((data) {
debugPrint("Deeplink Data :: $data");
var deeplinkData = jsonDecode(data);
var customParams = deeplinkData['customParams'];
///to reset deeplink data
_sdxfluttersdk.deepLinkDataReset();
if (customParams != null) {
screenNavigator(jsonDecode(customParams)['screenName'],jsonDecode(customParams)['data']);
}
});
}
Future<void> _getFcmToken() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
messaging.getToken().then((value) {
debugPrint('Fcm Token: $value');
setState(() {
token = value;
});
});
}
passLocation() {
double lat = 13.0827;
double lang = 80.2707;
_sdxfluttersdk.locationUpdate(lat, lang);
}
customEvent() {
var event = "On Track Event called!!!";
_sdxfluttersdk.customEvent(event);
}
customEventwithData() {
if (kIsWeb) {
//for web
var data = {
'eventName': 'Website Opened',
'eventData': 'Viewed Groceries',
'pId': 123,
};
_sdxfluttersdk.customEventWithData(data);
} else {
//for android & iOS
var eventData = {
"name": "payment",
"data": {"id": "6744", "price": "477"}
};
_sdxfluttersdk.customEventWithData(eventData);
}
}
deleteNotificationByCampaignid(campaignId) {
_sdxfluttersdk.deleteNotificationByCampaignId(campaignId);
}
readnotification(campaignId) {
_sdxfluttersdk.readNotification(campaignId);
}
unreadNotification(campaignId) {
_sdxfluttersdk.unReadNotification(campaignId);
}
appconversionTracking() {
_sdxfluttersdk.appConversion();
}
appconversionTrackingWithData() {
Map appConversionData = {
"name": "xyrr",
"data": {
"age": "23",
"city": "yyy"
}
};
_sdxfluttersdk.appConversionWithData(appConversionData);
}
formdataCapture() {
Map formData = {
"Name": "vishwa",
"EmailID": "[email protected]",
"MobileNo": 9329333,
"Gender": "Male",
"formid": 101, // required
"apikey": "b78db6rb3-9462-4132-a4d3-894db10b3782",
"City": "Chennai" // required
};
_sdxfluttersdk.formDataCapture(formData);
}
updatepushToken(fcmToken) {
_sdxfluttersdk.updatePushToken(fcmToken);
}
sdkRegisteration() {
if (kIsWeb) {
//for web
Map userData = {
"userUniqueId": "[email protected]",
"name": "<name>",
"age": "<age>",
"email": "<email>",
"phone": "<phone>",
"gender": "<gender>",
"profileUrl": "<profileUrl>",
"dateOfBirth": "<dob>",
};
_sdxfluttersdk.sdkRegisteration(userData);
}
else {
//for android & iOS
Map userData = {
"userUniqueId": "1111",
"name": "kkkkk",
"age": "23",
"email": "[email protected]",
"phone": "12334455",
"gender": "Male",
"profileUrl": "",
"dob": "23/12/2010",
"education": "BE",
"employed": "true",
"married": "false",
"deviceToken": token,
"storeId": "555"
};
_sdxfluttersdk.sdkRegisteration(userData);
}
}
readnotificationCount() async {
var rnCount = await _sdxfluttersdk.getReadNotificationCount();
if (kDebugMode) {
debugPrint("readNotificationCount::$rnCount");
}
}
unReadnotificationCount() async {
var unreadCount = await _sdxfluttersdk.getUnReadNotificationCount();
debugPrint("unReadNotificationCount::$unreadCount");
}
getNotificationList() async {
var notificationList = await _sdxfluttersdk.getNotificationList();
debugPrint("GetNotificationList::$notificationList");
}
@override
Widget build(BuildContext context) {
return MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
appBar: AppBar(
title: const Text('ReFlutter - Sdk'),
),
body: SingleChildScrollView(
child: ConstrainedBox(
constraints: const BoxConstraints(),
child: Container(
child: Column(
children: [
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () { //
sdkRegisteration();
}, child: const Text("On Device User Register"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
updatepushToken(token);
}, child: const Text("update Push Token"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
passLocation();
}, child: const Text("Update Location"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
readnotification(
"w39|G|qqD|iF|DEA5Q|430404|Bulk|20230418060124");
}, child: const Text("Read Notification By Id"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
unreadNotification(
"w39|G|qqD|iF|DEA5Q|430404|Bulk|20230418060124");
}, child: const Text("UnRead Notification BY Id"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
getNotificationList();
}, child: const Text("Get Notification List"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
readnotificationCount();
}, child: const Text("Read Notification Count"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
unReadnotificationCount();
},
child: const Text("Un_Read_Notification_Count"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
deleteNotificationByCampaignid(
"w39|G|qqD|iF|DEA5Q|430404|Bulk|20230418060124");
},
child: const Text(
"Delete Notification By CampaignId"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
formdataCapture();
}, child: const Text("form Data Capture"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
customEvent();
}, child: const Text("customEvent"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),);
customEventwithData();
}, child: const Text("customEventwithData"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
appconversionTracking();
}, child: const Text("app Conversion Tracking"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
ElevatedButton.styleFrom(
minimumSize: Size.fromHeight(40),);
appconversionTrackingWithData();
},
child: const Text(
"App Conversion Tracking WithData"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
ElevatedButton.styleFrom(
minimumSize: Size.fromHeight(40),);
WidgetsBinding.instance.addPostFrameCallback((_) {
_sdxfluttersdk.screentracking("page1");
});
}, child: const Text("Page-1"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),);
WidgetsBinding.instance.addPostFrameCallback((_) {
_sdxfluttersdk.screentracking("page2");
});
}, child: const Text("Page-2"),),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(onPressed: () {
ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),);
WidgetsBinding.instance.addPostFrameCallback((_) {
// Call the system service here
_sdxfluttersdk.screentracking("page3");
});
}, child: const Text("Page-3"),),
),
],
),
)
)
)
)
);
}
}
class Page1 extends StatelessWidget {
const Page1({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Page1')
],
),
),
);
}
}
class Page2 extends StatelessWidget {
const Page2({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Page2')
],
),
),
);
}
}
class Page3 extends StatelessWidget {
const Page3({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
),
body: const Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text('Page3')
],
),
),
);
}
}