customerglu_plugin 2.2.3
customerglu_plugin: ^2.2.3 copied to clipboard
Customerglu Flutter SDK With Entry-Points
example/lib/main.dart
import 'dart:convert';
// import 'package:customerglu_plugin_example/testScreen.dart';
// import 'package:firebase_core/firebase_core.dart';
// import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:customerglu_plugin_example/appplifecyclehandler.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:customerglu_plugin/customerglu_plugin.dart';
import 'LocalStore.dart';
import 'SplashScreen.dart';
import 'package:uni_links/uni_links.dart';
// Future<void> backgroundHandler(RemoteMessage message) async {
// print("backgroundHandler(RemoteMessage message)");
// await Firebase.initializeApp();
// CustomergluPlugin.displayCustomerGluBackgroundNotification(message.data);
// }
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
final lifecycleHandler = AppLifecycleHandler();
WidgetsBinding.instance.addObserver(lifecycleHandler);
CustomergluPlugin.initSDK("in");
// await Firebase.initializeApp();
//FirebaseMessaging.onBackgroundMessage(backgroundHandler);
SystemChrome.setPreferredOrientations(
[DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
runApp(MyApp());
});
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
var fcmtoken = "";
StreamSubscription? _sub;
static const broadcast_channel = MethodChannel("CUSTOMERGLU_EVENTS");
@override
void dispose() {
_sub?.cancel();
super.dispose();
}
@override
void initState() {
super.initState();
// Firebase.initializeApp();
print("YAHOOOOOOOOOOO 00000");
// initUniLinks();
// FirebaseMessaging.instance.getInitialMessage().then((message) async {
// print("FirebaseMessaging.instance.getInitialMessage().then((message)");
// if (message != null) {
// CustomergluPlugin.displayCustomerGluBackgroundNotification(
// message.data);
// }
// });
// var messaging = FirebaseMessaging.instance;
CustomergluPlugin.handleCGDeepLink();
// messaging.getToken().then((value) {
// print("fcm token" + value.toString());
// fcmtoken = value!;
// LocalStore().setAppSharePopUp(fcmtoken);
// });
// FirebaseMessaging.onMessage.listen((message) {
// print("FirebaseMessaging.onMessage.listen");
// CustomergluPlugin.displayCustomerGluNotification(message.data,
// autoclosewebview: true, opacity: 0.5);
// });
// FirebaseMessaging.onMessageOpenedApp.listen((message) {
// print("FirebaseMessaging.onMessageOpenedApp.listen");
// CustomergluPlugin.displayCustomerGluBackgroundNotification(message.data);
// });
broadcast_channel.setMethodCallHandler((call) async {
print("home method channel");
switch (call.method) {
case "CUSTOMERGLU_DEEPLINK_EVENT":
print("CUSTOMERGLU_DEEPLINK_EVENT");
print(call.arguments);
var json = jsonDecode(call.arguments);
print(json["name"]);
break;
case "CUSTOMERGLU_ANALYTICS_EVENT":
print("CUSTOMERGLU_ANALYTICS_EVENT FROM FLUTTER");
print(call.arguments);
var json = jsonDecode(call.arguments);
print(json["event_name"]);
break;
case "CG_UNI_DEEPLINK_EVENT":
print("CG_UNI_DEEPLINK_EVENT FROM FLUTTER");
print(call.arguments);
var json = jsonDecode(call.arguments);
break;
case "CUSTOMERGLU_BANNER_LOADED":
print("CUSTOMERGLU_BANNER_LOADED");
print(call.arguments);
break;
case "CG_INVALID_CAMPAIGN_ID":
print("CG_INVALID_CAMPAIGN_ID");
print(call.arguments);
break;
}
});
CustomergluPlugin.enableAnalyticsEvent(true);
//CustomergluPlugin.configureLoaderColour("#0B66EA");
}
// Future<void> initUniLinks() async {
// // ... check initialUri
//
// // Attach a listener to the stream
// _sub = uriLinkStream.listen((Uri? uri) {
// print("YAOOOOOOOO");
// print("uri "+uri.toString());
// // Use the uri and warn the user, if it is not correct
// }, onError: (err) {
// // Handle exception by warning the user their action did not succeed
// });
//
// // NOTE: Don't forget to call _sub.cancel() in dispose()
// }
static const EventChannel _eventChannel = EventChannel("CustomerGlu");
late StreamSubscription _mystream;
// Platform messages are asynchronous, so we initialize in an async method.
Future<void> initPlatformState() async {
String platformVersion;
try {} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
if (!mounted) return;
setState(() {});
}
@override
Widget build(BuildContext context) {
return const MaterialApp(
debugShowCheckedModeBanner: false, home: SplashScreen());
}
}