flyy_flutter_plugin 1.0.23
flyy_flutter_plugin: ^1.0.23 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:flutter/services.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 != null &&
remoteMessage.data != null &&
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> {
FirebaseMessaging firebaseMessaging;
@override
void initState() {
super.initState();
setupFirebase();
//To set your package name same as entered in Flyy Dashboard
//this method is only for ios
FlyyFlutterPlugin.setPackageName("com.theflyy.flyy_flutter_plugin_example");
initFlyySdk();
}
setupFirebase() {
// await Firebase.initializeApp();
firebaseMessaging = FirebaseMessaging.instance;
firebaseMessaging.getToken().then((value) {
print(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 != null &&
remoteMessage.data != null &&
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() {
// FlyyFlutterPlugin.setPackageName("com.roidtechnologies.appbrowzer");
//init sdk with your partner token and environment (staging/production)
FlyyFlutterPlugin.initFlyySDKWithReferralCallback(
"<partner-id>", FlyyFlutterPlugin.PRODUCTION);
}
Future<void> callSetUser() async {
// FlyyFlutterPlugin.setFlyyReferralCode("23ftho9");
FlyyFlutterPlugin.setFlyyUser("9876543210");
//set user name
FlyyFlutterPlugin.setFlyyUserName("User Name");
// 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);
}
// //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();
// 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'),
),
),
),
),
);
}
}