resfluttersdkautomation_dfc8a6_23_4md5_a948_bd52d352b182 1.0.5
resfluttersdkautomation_dfc8a6_23_4md5_a948_bd52d352b182: ^1.0.5 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 'dart:async';
import 'dart:convert';
import 'dart:developer';
import 'package:flutter/material.dart';
import 'package:firebase_messaging/firebase_messaging.dart'
if (dart.library.io) 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_core/firebase_core.dart'
if (dart.library.io) 'package:firebase_core/firebase_core.dart';
import 'package:flutter/foundation.dart';
import 'package:resfluttersdkautomation/refluttersdk.dart';
void main() async {
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS) {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
// Initialize Firebase
FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
await setupFirebaseMessaging();
}
runApp(const MyApp());
}
Future<void> setupFirebaseMessaging() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
String? token = await messaging.getToken();
print("FCM Token: $token");
// Handle foreground messages
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
print("Message received: ${message.data}");
_refluttersdkPlugin.onReceivedCampaign(message.data);
// Handle the message here
});
// Handle background messages
// FirebaseMessaging.onBackgroundMessage(_firebaseMessagingBackgroundHandler);
}
@pragma('vm:entry-point')
Future<void> _firebaseMessagingBackgroundHandler(RemoteMessage message) async {
print("Background message: ${message.data}");
_refluttersdkPlugin.onReceivedCampaign(message.data);
}
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(
title: 'resfluttersdkautomation-Example',
debugShowCheckedModeBanner: false,
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 Home Page'),
);
}
}
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 _refluttersdkPlugin = Refluttersdk();
method() async {
_refluttersdkPlugin.unReadNotification("CampaignId");
}
class _MyHomePageState extends State<MyHomePage> {
var token = "ADkekowiksi3ieje93jowi3sdkjie";
StreamSubscription<String>? streamSubscription;
@override
void initState() {
super.initState();
if (kIsWeb) {
_refluttersdkPlugin.initWebSDK("./sw.js");
}
if (defaultTargetPlatform == TargetPlatform.android ||
defaultTargetPlatform == TargetPlatform.iOS) {
_getFcmToken();
}
deeplinkListener();
getDeeplinkData();
// if (defaultTargetPlatform == TargetPlatform.android) {
// deeplinkListener();
// } else {
// getDeeplinkData();
// }
}
deeplinkListener() {
streamSubscription =
_refluttersdkPlugin.listenDeeplinkData().listen((data) async {
try {
debugPrint('DeepLink Listener :: $data');
var deeplinkData = jsonDecode(data);
var customParams = deeplinkData['customParams'];
///to reset deeplink data
_refluttersdkPlugin.deepLinkDataReset();
if (customParams != null) {
screenNavigator(jsonDecode(customParams)['screenName'],
jsonDecode(customParams)['data']);
}
} catch (e) {
debugPrint('$e');
}
});
}
getDeeplinkData() {
_refluttersdkPlugin.listener((data) {
debugPrint("Deeplink Data :: $data");
var deeplinkData = jsonDecode(data);
var customParams = deeplinkData['customParams'];
///to reset deeplink data
_refluttersdkPlugin.deepLinkDataReset();
if (customParams != null) {
screenNavigator(jsonDecode(customParams)['screenName'],
jsonDecode(customParams)['data']);
}
});
}
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!!!");
}
}
}
Future<void> _getFcmToken() async {
FirebaseMessaging messaging = FirebaseMessaging.instance;
messaging.getToken().then((value) {
debugPrint('Fcm Token: $value');
log('Fcm Token: $value');
setState(() {
token = value!;
});
});
}
passLocation() {
double lat = 13.0827;
double lang = 80.2707;
_refluttersdkPlugin.locationUpdate(lat, lang);
}
customEvent() {
var event = "On Track Event called!!!";
_refluttersdkPlugin.customEvent(event);
}
customEventwithData() {
if (kIsWeb) {
//for web
var data = {
'eventName': 'Website Opened',
'eventData': 'Viewed Groceries',
'pId': 123,
};
_refluttersdkPlugin.customEventWithData(data);
} else {
//for android & iOS
var eventData = {
"name": "payment",
"data": {"id": "6744", "price": "477"}
};
_refluttersdkPlugin.customEventWithData(eventData);
}
}
deleteNotificationByCampaignid(campaignId) {
_refluttersdkPlugin.deleteNotificationByCampaignId(campaignId);
}
readnotification(campaignId) {
_refluttersdkPlugin.readNotification(campaignId);
}
unreadNotification(campaignId) {
_refluttersdkPlugin.unReadNotification(campaignId);
}
appconversionTracking() {
_refluttersdkPlugin.appConversion();
}
appconversionTrackingWithData() {
Map appConversionData = {
"name": "xyrr",
"data": {"age": "23", "city": "yyy"}
};
_refluttersdkPlugin.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
};
_refluttersdkPlugin.formDataCapture(formData);
}
updatepushToken(fcmToken) {
_refluttersdkPlugin.updatePushToken(fcmToken);
}
notificationCTAClick(String campaignId, int actionId) {
_refluttersdkPlugin.notificationCTAClicked(campaignId, actionId);
}
sdkRegisteration() {
if (kIsWeb) {
//for web
Map userData = {
"userUniqueId": "[email protected]",
"name": "visionUser",
"age": "23",
"email": "[email protected]",
"phone": "9393939392",
"gender": "Male",
"profileUrl": "",
"dateOfBirth": "13/7/2003",
};
_refluttersdkPlugin.sdkRegisteration(userData);
} else {
//for android & iOS
Map userData = {
"userUniqueId": "[email protected]",
"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"
};
_refluttersdkPlugin.sdkRegisteration(userData);
}
}
readnotificationCount() async {
var rnCount = await _refluttersdkPlugin.getReadNotificationCount();
if (kDebugMode) {
debugPrint("readNotificationCount::$rnCount");
}
}
unReadnotificationCount() async {
var unreadCount = await _refluttersdkPlugin.getUnReadNotificationCount();
debugPrint("unReadNotificationCount::$unreadCount");
}
getNotificationList() async {
var notificationList = await _refluttersdkPlugin.getNotificationList();
debugPrint("GetNotificationList::$notificationList");
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text(
'resfluttersdkautomation',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
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: const Size.fromHeight(40),
);
appconversionTrackingWithData();
},
child: const Text("App Conversion Tracking WithData"),
),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),
);
notificationCTAClick(
"w39|G|qqD|iF|DEA5Q|430404|Bulk|20230418060124",
4833);
},
child: const Text("NotificationCTA clicked"),
),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),
);
WidgetsBinding.instance.addPostFrameCallback((_) {
_refluttersdkPlugin.screentracking("page1");
});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const Page1()));
},
child: const Text("Page-1"),
),
),
SizedBox(
width: double.infinity,
child: ElevatedButton(
onPressed: () {
ElevatedButton.styleFrom(
minimumSize: const Size.fromHeight(40),
);
WidgetsBinding.instance.addPostFrameCallback((_) {
_refluttersdkPlugin.screentracking("page2");
});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const 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
_refluttersdkPlugin.screentracking("page3");
});
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => const 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')],
),
),
);
}
}