flyy_flutter_plugin 1.1.104
flyy_flutter_plugin: ^1.1.104 copied to clipboard
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';
import 'package:flyy_flutter_plugin/widgets/flyy_custom_checkin_view.dart';
import 'package:flyy_flutter_plugin/widgets/flyy_stories.dart';
import 'package:flyy_flutter_plugin/flyy_flutter_plugin_screentracking.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;
FlyyScreenTracking _flyyScreenTracking = FlyyScreenTracking();
@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>");
_flyyScreenTracking.addNewListener(onScreenVisit: (data) {
print("Screen TEST :::");
print(data);
});
FlyyFlutterPlugin.setPackageName("com.testapp");
initFlyySdk();
FlyyFlutterPlugin.trackUIEvents();
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("fe9be1d2d901351e4bd6", FlyyFlutterPlugin.STAGE);
FlyyFlutterPlugin.setThemeColor('#F26E38', '#cc1d27');
//FlyyFlutterPlugin.navigateToHome(shouldNavigateToHome: true, noQuizLiveMsg: "No quiz live", quizCompletionMsg: "Get 30 leo coin on every question answer you will find these");
//FlyyFlutterPlugin.setReferralCodeHide(true);
//FlyyFlutterPlugin.setDarkThemeColor();
FlyyFlutterPlugin.setFlyyUser("peter1");
FlyyFlutterPlugin.setFlyyUserName("peter1");
FlyyFlutterPlugin.setCustomQuizPageEnabled(false);
// FlyyFlutterPlugin.setInviteAndEarnTitle(true, "Earn");
FlyyFlutterPlugin.setPSTQConfig(logoUrl: "https://res.cloudinary.com/dfrwod0ew/image/upload/v1661840760/samples/cloudinary-icon.png", hideLogo: false, thankYouTitle: "Manjit", thankYouDescription: "Bhullar", primaryTextColor: "#F26E38", buttonBgColor: "#06DE0F", buttonBgSecondaryColor: "#0A324B", buttonTextColor: "#FFFFFF", seekbarColor: "#477BFF", descriptionColor: "#A4A6BA");
//FlyyFlutterPlugin.updateSCGiftCardButton("close", true);
//FlyyFlutterPlugin.openFlyyPollListScreen();
//FlyyFlutterPlugin.setReferralHistoryEnableInviteAndEarn(true);
//FlyyFlutterPlugin.hideSCPopupDetails(hideScRefNum: true, hideScDate: true);
//FlyyFlutterPlugin.navigateToHome(shouldNavigateToHome: true,noQuizLiveMsg: "No Quiz Live",quizCompletionMsg: "Quiz Completed",checkedInButtonText: "YOYO");
//FlyyFlutterPlugin.setCustomFontName("OpenSans-MediumItalic.ttf", "OpenSans-MediumItalic.ttf", "OpenSans-MediumItalic.ttf");
//FlyyFlutterPlugin.openFlyyBonanzaPage();
//FlyyFlutterPlugin.setKYCStatus(false, "https://google.com");
// FlyyFlutterPlugin.setFlyyUser("<user_id>");
// FlyyFlutterPlugin.setFlyyUserName("<user_name>");
// var data = await FlyyFlutterPlugin.initFlyySDKWithReferralCallback("fee9c537c4559391f4bf", FlyyFlutterPlugin.PRODUCTION);
// if(data != null)
// {
// if(data.length > 1)
// {
// var xReferralCode = await FlyyFlutterPlugin.getFlyyReferralCode();
// var mapResult = await FlyyFlutterPlugin.verifyReferralCode(xReferralCode);
// print(mapResult);
// if(mapResult["is_valid"])
// {
// var referrerCode = mapResult["referral_code"];
// print("Screen referral :::");
// print(referrerCode);
// }
// }
// }
}
@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: () async {
FlyyFlutterPlugin.openFlyyOffersPage();
//FlyyFlutterPlugin.openFlyyReatilerIncentiveApp("7a09ca9802cbe1556d3e", "sh9ysQ0OLU", "#FFA500", "ops.pharmarack-rt");
//FlyyFlutterPlugin.openFlyySurveyScreen(357);
//FlyyFlutterPlugin.openFlyySurveyListScreen();
// 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();
// String referralCode =
// await FlyyFlutterPlugin.getFlyyReferralCode();
// var mapResult = await FlyyFlutterPlugin.verifyReferralCode(
// referralCode);
// print("REFERRAL CODE ::: ${mapResult}");
},
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,
),
// Container(
// height: 155,
// child: FlyyStories(),
// )
// FlyyFlutterPlugin.flyyWidget()
FlyyCustomCheckInView()
],
),
),
),
),
);
}
}