flyy_flutter_plugin 1.1.0
flyy_flutter_plugin: ^1.1.0 copied to clipboard
Flutter wrapper around our Android and iOS mobile SDKs
example/lib/main.dart
import 'dart:async';
import 'package:firebase_core/firebase_core.dart';
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/material.dart';
import 'package:flyy_flutter_plugin/flyy_flutter_plugin.dart';
//comes here when app is in background
Future<void> _messageHandler(RemoteMessage remoteMessage) async {
print('background message ${remoteMessage.notification!.body}');
handleNotification(remoteMessage);
}
handleNotification(RemoteMessage remoteMessage) {
if (remoteMessage.data.containsKey("notification_source") &&
remoteMessage.data["notification_source"] != null &&
remoteMessage.data["notification_source"] == "flyy_sdk") {
FlyyFlutterPlugin.handleNotification(remoteMessage.data);
}
}
Future<void> main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
FirebaseMessaging.onBackgroundMessage(_messageHandler);
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
late FirebaseMessaging firebaseMessaging;
@override
void initState() {
super.initState();
//To set your package name same as entered in Flyy Dashboard
FlyyFlutterPlugin.setPackageName("<package_name>");
initFlyySdk();
setupFirebase();
}
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(value);
FlyyFlutterPlugin.sendFCMTokenToServer(value!);
});
//comes here when app is in foreground
FirebaseMessaging.onMessage.listen((RemoteMessage remoteMessage) {
handleNotification(remoteMessage);
print("message recieved");
print(remoteMessage.notification!.body);
});
//comes here when clicked from notification bar
FirebaseMessaging.onMessageOpenedApp.listen((remoteMessage) {
handleNotification(remoteMessage);
print('Message clicked!');
});
}
handleNotification(RemoteMessage remoteMessage) {
if (remoteMessage.data.containsKey("notification_source") &&
remoteMessage.data["notification_source"] != null &&
remoteMessage.data["notification_source"] == "flyy_sdk") {
FlyyFlutterPlugin.handleNotification(remoteMessage.data);
}
}
// Platform messages are asynchronous, so we initialize in an async method.
initFlyySdk() async {
FlyyFlutterPlugin.initFlyySDK("<partner_id>", FlyyFlutterPlugin.STAGE);
FlyyFlutterPlugin.setThemeColor("#cc1d27", "#cc1d27");
FlyyFlutterPlugin.setFlyyUser("<user_id>");
FlyyFlutterPlugin.setFlyyUserName("<user_name>");
}
Future<void> callSetUser() async {
// FlyyFlutterPlugin.setFlyyReferralCode("23ftho9");
// FlyyFlutterPlugin.setFlyyUserToken("<user_token>");
// String result = await FlyyFlutterPlugin.setFlyyUserToken("<user_token>");
// print(result);
// FlyyFlutterPlugin.setFlyyNewUserToken("<user_token>");
// String result = await FlyyFlutterPlugin.setFlyyNewUserToken("<user_token>");
// print(result);
//set user name
// FlyyFlutterPlugin.setFlyyNewUserTokenWithSegment("ADvK12M", "all_users");
//
// result = await FlyyFlutterPlugin.setFlyyUserTokenWithSegment(
// "ADvK12M", "all_users");
// Map<String, dynamic> mapResult =
// await FlyyFlutterPlugin.verifyReferralCode("asdkjjkj23");
//
// //To get result
// print(mapResult["is_valid"]);
// print(mapResult["referral_code"]);
// try {
// Map<String, dynamic> mapShareData =
// await FlyyFlutterPlugin.getShareData();
//
// //To get result
// print(mapShareData["referral_link"]);
// print(mapShareData["referral_message"]);
// print(mapShareData["share_message"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
//
// try {
// int referralCount = await FlyyFlutterPlugin.getReferralCount();
//
// //To get result
// print(referralCount);
// } on PlatformException catch (e) {
// print(e.message);
// }
// String referralCode = await FlyyFlutterPlugin.getFlyyReferralCode();
// try {
// Map<String, dynamic> mapShareData =
// await FlyyFlutterPlugin.getScratchCardCount();
//
// //To get result
// print(mapShareData["total_sc_count"]);
// print(mapShareData["scratched_sc_count"]);
// print(mapShareData["unscratched_sc_count"]);
// print(mapShareData["locked_sc_count"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
// try {
// Map<String, dynamic> mapShareData =
// await FlyyFlutterPlugin.getPreviousLeaderboardWinners("test");
//
// //To get result
// print(mapShareData["participants_count"]);
// print(mapShareData["winners"]);
// print(mapShareData["previous_winners"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
// try {
// Map<String, dynamic> mapShareData =
// await FlyyFlutterPlugin.getWalletBalance("cash");
//
// //To get result
// print(mapShareData["balance"]);
// print(mapShareData["total_credit"]);
// print(mapShareData["total_debit"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
// try {
// Map<String, dynamic> mapShareData1 =
// await FlyyFlutterPlugin.getReferrerDetails();
//
// //To get result
// print(mapShareData1["name"]);
// print(mapShareData1["ext_uid"]);
// print(mapShareData1["extra_data"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
// try {
// Map<String, dynamic> mapShareData2 =
// await FlyyFlutterPlugin.getOffersCount();
//
// //To get result
// print(mapShareData2["live_offers_count"]);
// print(mapShareData2["participated_offers_count"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
// try {
// Map<String, dynamic> mapShareData3 =
// await FlyyFlutterPlugin.trackUIEvents();
//
// //To get result
// print(mapShareData3["campaign_id"]);
// print(mapShareData3["campaign_name"]);
// print(mapShareData3["wallet_type"]);
// print(mapShareData3["wallet_label"]);
// print(mapShareData3["user_id"]);
// print(mapShareData3["action_event_name"]);
// print(mapShareData3["created_at"]);
// } on PlatformException catch (e) {
// print(e.message);
// }
// //send event with key and value as strings
// await FlyyFlutterPlugin.sendEvent("flutter_plugin_android", "test");
//
// //send event key as string and value as json data in map
// Map<String, String> jsonData = new Map();
// jsonData['json_test'] = 'success';
// jsonData['flutter_plugin'] = "tested";
// String result =
// await FlyyFlutterPlugin.sendJSONEvent("flutter_plugin", jsonData);
// if (result == "success") {
// //do your work here
// }
callOfferPage();
}
Future<void> callOfferPage() async {
FlyyFlutterPlugin.openFlyyOffersPage();
String result = await FlyyFlutterPlugin.onFlyySDKClosed();
print(result);
// FlyyFlutterPlugin.openFlyyCustomInviteAndEarnPage(0, "#cc1d27");
// FlyyFlutterPlugin.openFlyyInviteAndEarnPage(0);
// FlyyFlutterPlugin.openFlyyBonanzaPage();
// FlyyFlutterPlugin.openFlyyChallengeDetailsPage(0);
// FlyyFlutterPlugin.openFlyyReferralsPage();
// FlyyFlutterPlugin.openFlyyRewardsPage();
// FlyyFlutterPlugin.openFlyyWalletPage();
// FlyyFlutterPlugin.openFlyyGiftCardsPage();
// FlyyFlutterPlugin.openFlyyReferralsPage();
// FlyyFlutterPlugin.openFlyyQuizPage();
// FlyyFlutterPlugin.openFlyyQuizListPage();
// FlyyFlutterPlugin.openFlyyQuizHistoryPage();
// FlyyFlutterPlugin.openFlyyStampsPage();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('Plugin example app'),
),
body: GestureDetector(
onTap: () {
callSetUser();
},
child: Padding(
padding: const EdgeInsets.all(20.0),
child: Center(
child: Text('Start Flyy'),
),
),
),
),
);
}
}