cgdemoplugin 0.0.1 cgdemoplugin: ^0.0.1 copied to clipboard
A new Flutter project.
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:cgdemoplugin/cgdemoplugin.dart';
import 'LocalStore.dart';
import 'SplashScreen.dart';
Future<void> backgroundHandler(RemoteMessage message) async {
print("backgroundHandler(RemoteMessage message)");
await Firebase.initializeApp();
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(backgroundHandler);
// final NotificationAppLaunchDetails? notificationAppLaunchDetails =
// await flutterLocalNotificationsPlugin.getNotificationAppLaunchDetails();
// if (notificationAppLaunchDetails?.didNotificationLaunchApp ?? false) {
// // runApp(MyApp());
// // selectedNotificationPayload =
// // notificationAppLaunchDetails!.payload.toString();
// selectedNotificationPayload = await LocalStore().getAppSharePopUp();
// myurl = selectedNotificationPayload;
// print(myurl);
// SystemChrome.setPreferredOrientations(
// [DeviceOrientation.portraitUp, DeviceOrientation.portraitDown]).then((_) {
// runApp(MyApp());
// });
// } else {
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 = "";
static const broadcast_channel = MethodChannel("CUSTOMERGLU_EVENTS");
@override
void initState() {
super.initState();
Firebase.initializeApp();
FirebaseMessaging.instance.getInitialMessage().then((message) async {
print("FirebaseMessaging.instance.getInitialMessage().then((message)");
if (message != null) {
if (message.data["type"] != null &&
message.data["type"] == "CustomerGlu") print("initial");
}
});
var messaging = FirebaseMessaging.instance;
messaging.getToken().then((value) {
print("fcm token" + value.toString());
fcmtoken = value!;
Cgdemoplugin.setApnFcmToken("", fcmtoken);
LocalStore().setAppSharePopUp(fcmtoken);
// var profile = {'': ''};
// DemoPlugin.updateProfile(profile);
//Firebase Token
});
FirebaseMessaging.onMessage.listen((message) {
print("FirebaseMessaging.onMessage.listen");
Cgdemoplugin.displayCustomerGluNotification(message.data);
});
FirebaseMessaging.onMessageOpenedApp.listen((message) {
print("FirebaseMessaging.onMessageOpenedApp.listen");
Cgdemoplugin.displayBackgroundNotification(message.data);
});
broadcast_channel.setMethodCallHandler((call) async {
switch (call.method) {
case "CUSTOMERGLU_DEEPLINK_EVENT":
print("CUSTOMERGLU_DEEPLINK_EVENT");
print(call.arguments);
break;
case "CUSTOMERGLU_ANALYTICS_EVENT":
print("CUSTOMERGLU_ANALYTICS_EVENT");
print(call.arguments);
break;
}
});
Cgdemoplugin.enableAnalyticsEvent(true);
Cgdemoplugin.configureLoaderColour("#0B66EA");
}
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;
// Platform messages may fail, so we use a try/catch PlatformException.
// We also handle the message potentially returning null.
try {
// var profile = {'userId': 'JohnWick'};
// await DemoPlugin.getInstance();
// await DemoPlugin.doRegister(profile, true);
// await DemoPlugin.enablePrecaching();
// await DemoPlugin.platformVersion ?? 'Unknown platform version';
} on PlatformException {
platformVersion = 'Failed to get platform version.';
}
// If the widget was removed from the tree while the asynchronous platform
// message was in flight, we want to discard the reply rather than calling
// setState to update our non-existent appearance.
if (!mounted) return;
setState(() {
// _platformVersion = platformVersion;
});
}
// Future<void> openWallet() async {
// await DemoPlugin.openWallet();
// }
@override
Widget build(BuildContext context) {
// listenBroadcast();
return const MaterialApp(
debugShowCheckedModeBanner: false, home: SplashScreen());
}
}