flyy_flutter_plugin 1.4.3 copy "flyy_flutter_plugin: ^1.4.3" to clipboard
flyy_flutter_plugin: ^1.4.3 copied to clipboard

PlatformAndroidiOS
outdated

Flutter wrapper around our Android and iOS mobile SDKs

example/lib/main.dart

import 'dart:async';
import 'dart:io';

import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flyy_flutter_plugin/flyy_flutter_plugin.dart';

//comes here when app is in background
//handle notification as per the platform
Future<void> _messageHandler(RemoteMessage remoteMessage) async {
  print('background message ${remoteMessage.notification!.body}');
  if (Platform.isAndroid) {
    //for android
    handleAndroidNotification(remoteMessage);
  } else if (Platform.isIOS) {
    //for ios
    handleiOSNotification(remoteMessage);
  }
}

//handle flyy android notifications
handleAndroidNotification(RemoteMessage remoteMessage) {
  print('background message ${remoteMessage.notification!.body}');
  if (remoteMessage.data.containsKey("notification_source") &&
      remoteMessage.data["notification_source"] != null &&
      remoteMessage.data["notification_source"] == "flyy_sdk") {
    FlyyFlutterPlugin.handleNotification(remoteMessage.data);
  }
}

//handle flyy ios notifications
handleiOSNotification(RemoteMessage remoteMessage) {
  print('background message ${remoteMessage.notification!.body}');
  if (remoteMessage.data.containsKey("notification_source") &&
      remoteMessage.data["notification_source"] != null &&
      remoteMessage.data["notification_source"] == "flyy_sdk") {
    FlyyFlutterPlugin.handleBackgroundNotification(remoteMessage.data);
  }
}

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await Firebase.initializeApp();
  FirebaseMessaging.onBackgroundMessage(_messageHandler);
  runApp(MyHome());
}

class MyHome extends StatelessWidget {
  const MyHome({Key? key}) : super(key: key);

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flyy Demo',
      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: MyApp(),
    );
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  late FirebaseMessaging firebaseMessaging;

  late FlyyFlutterPlugin flyy;

  @override
  void initState() {
    super.initState();

    flyy = FlyyFlutterPlugin();
    flyy.on(FlyyFlutterPlugin.FLYY_ON_SDK_CLOSED_LISTENER, onFlyySdkClosed);
    flyy.on(
        FlyyFlutterPlugin.FLYY_INIT_WITH_REFERRAL_CALLBACK, onReferralSuccess);

    //FlyyFlutterPlugin.setPackageName("<package_name_same_as_flyy_dashboard>");
    FlyyFlutterPlugin.setPackageName("theflyy.com.flyysdk");
    initFlyySdk();
    setupFirebase();
  }

  //do your work here when flyy sdk is closed
  void onFlyySdkClosed(String response) {
    if (response != null) {
      getWalletBalance();
    }
  }

  void onReferralSuccess(String referralData) {
    if (referralData != null) {
      FlyyFlutterPlugin.verifyReferralCode(referralData);
    }
  }

  getWalletBalance() async {
    try {
      Map<String, dynamic> mapShareData =
          await FlyyFlutterPlugin.getWalletBalance("<your_currency>");

      //To get result
      print(mapShareData["balance"]);
      print(mapShareData["total_credit"]);
      print(mapShareData["total_debit"]);
    } on PlatformException catch (e) {
      print(e.message);
    }
  }

  @override
  void dispose() {
    super.dispose();
    flyy.clearEventListeners();
  }

  setupFirebase() async {
    // await Firebase.initializeApp();
    // Code added to display user authorization for notifications

    FirebaseMessaging messaging = FirebaseMessaging.instance;
    NotificationSettings settings = await messaging.requestPermission(
      alert: true,
      announcement: false,
      badge: true,
      carPlay: false,
      criticalAlert: false,
      provisional: false,
      sound: true,
    );

    if (settings.authorizationStatus == AuthorizationStatus.authorized) {
      print('User granted permission');
    } else if (settings.authorizationStatus ==
        AuthorizationStatus.provisional) {
      print('User granted provisional permission');
    } else {
      print('User declined or has not accepted permission');
    }

    firebaseMessaging = FirebaseMessaging.instance;
    firebaseMessaging.getToken().then((value) {
      print("FCM TOKEN :- $value");
      //send fcm token to server only for ios
      FlyyFlutterPlugin.sendFCMTokenToServer(value!);
    });

    //comes here when app is in foreground
    FirebaseMessaging.onMessage.listen((RemoteMessage remoteMessage) {
      print("message received");
      print(remoteMessage.data);
      if (Platform.isAndroid) {
        handleAndroidNotification(remoteMessage);
      } else if (Platform.isIOS) {
        handleiOSNotification(remoteMessage);
      }
    });

    //comes here when clicked from notification bar
    FirebaseMessaging.onMessageOpenedApp.listen((remoteMessage) {
      print('Message clicked!');
      if (Platform.isAndroid) {
        //do nothing for android
      } else if (Platform.isIOS) {
        handleiOSNotification(remoteMessage);
      }
    });
  }

  //handle flyy android notifications
  handleAndroidNotification(RemoteMessage remoteMessage) {
    print('background message ${remoteMessage.notification!.body}');
    if (remoteMessage.data.containsKey("notification_source") &&
        remoteMessage.data["notification_source"] != null &&
        remoteMessage.data["notification_source"] == "flyy_sdk") {
      FlyyFlutterPlugin.handleNotification(remoteMessage.data);
    }
  }

  //handle flyy ios notifications
  handleiOSNotification(RemoteMessage remoteMessage) {
    print('background message ${remoteMessage.notification!.body}');
    if (remoteMessage.data.containsKey("notification_source") &&
        remoteMessage.data["notification_source"] != null &&
        remoteMessage.data["notification_source"] == "flyy_sdk") {
      FlyyFlutterPlugin.handleForegroundNotification(remoteMessage.data);
    }
  }

  // Platform messages are asynchronous, so we initialize in an async method.
  initFlyySdk() async {
    //FlyyFlutterPlugin.initFlyySDK("<partner_id>", FlyyFlutterPlugin.PRODUCTION);
    FlyyFlutterPlugin.initFlyySDK(
        "8fce343fa6170bf1ecb5", FlyyFlutterPlugin.STAGE);
    FlyyFlutterPlugin.setThemeColor('#ce1d67', '#cc1d27');
    FlyyFlutterPlugin.setFlyyUser("8437327307");
    FlyyFlutterPlugin.setFlyyUserName("Vishal");
    // FlyyFlutterPlugin.setFlyyUser("<user_id>");
    // FlyyFlutterPlugin.setFlyyUserName("<user_name>");
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: Center(
          child: Container(
            child: Column(
              children: [
                GestureDetector(
                  onTap: () {
                    FlyyFlutterPlugin.openFlyyOffersPage();
                    // FlyyFlutterPlugin.openFlyyStampsPage();
                    // FlyyFlutterPlugin.openFlyyStampsV1Page();
                    // FlyyFlutterPlugin.openFlyyRafflePage(114);
                    // FlyyFlutterPlugin.openFlyySpinTheWheelPage(0);
                    //FlyyFlutterPlugin.openFlyyRewardsPage();
                    // FlyyFlutterPlugin.openFlyyWalletPage();
                    // FlyyFlutterPlugin.openFlyyGiftCardsPage();
                    // FlyyFlutterPlugin.openFlyyReferralsPage();
                    // FlyyFlutterPlugin.openFlyyQuizPage(0);
                    // FlyyFlutterPlugin.openFlyyQuizHistoryPage();
                    // FlyyFlutterPlugin.openFlyyQuizListPage();
                    //FlyyFlutterPlugin.openFlyyInviteDetailsPage(0);
                    // FlyyFlutterPlugin.openFlyyInviteAndEarnPage(0);
                    // FlyyFlutterPlugin.openFlyyCustomInviteAndEarnPage(0, "");
                    // FlyyFlutterPlugin.openFlyyChallengeDetailsPage(0);
                    // FlyyFlutterPlugin.openFlyyBonanzaPage();
                  },
                  child: Padding(
                    padding: const EdgeInsets.all(20.0),
                    child: Center(
                      child: Text('Start Offers Page'),
                    ),
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    // FlyyFlutterPlugin.listenFlyySDKClosed();
                    FlyyFlutterPlugin.openFlyyRewardsPage();
                  },
                  child: Padding(
                    padding: const EdgeInsets.all(20.0),
                    child: Center(
                      child: Text('Start Rewards Page'),
                    ),
                  ),
                ),
                GestureDetector(
                  onTap: () {
                    FlyyFlutterPlugin.openFlyyWalletPage();
                    // FlyyFlutterPlugin.openFlyyReferralsPage();
                  },
                  child: Padding(
                    padding: const EdgeInsets.all(20.0),
                    child: Center(
                      child: Text('Start Wallet Page'),
                    ),
                  ),
                ),
                SizedBox(
                  height: 20,
                ),
                // FlyyFlutterPlugin.flyyWidget()
              ],
            ),
          ),
        ),
      ),
    );
  }
}
5
likes
140
points
967
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter wrapper around our Android and iOS mobile SDKs

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

eventify, flutter

More

Packages that depend on flyy_flutter_plugin

Packages that implement flyy_flutter_plugin