customerglu_plugin 0.0.2 copy "customerglu_plugin: ^0.0.2" to clipboard
customerglu_plugin: ^0.0.2 copied to clipboard

outdated

Customerglu Flutter SDK

example/lib/main.dart

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:customerglu_plugin/customerglu_plugin.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);
  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!;
      LocalStore().setAppSharePopUp(fcmtoken);
    });

    FirebaseMessaging.onMessage.listen((message) {
      print("FirebaseMessaging.onMessage.listen");
      CustomergluPlugin.displayCustomerGluNotification(message.data);
    });

    FirebaseMessaging.onMessageOpenedApp.listen((message) {
      print("FirebaseMessaging.onMessageOpenedApp.listen");
      CustomergluPlugin.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;
      }
    });
    CustomergluPlugin.enableAnalyticsEvent(true);
    CustomergluPlugin.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;
    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());
  }
}