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

Flutter wrapper around our Android and iOS mobile SDKs

example/lib/main.dart

import 'dart:async';
import 'dart:convert';
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';
// import 'package:flyy_flutter_plugin_example/login.dart';
// import 'package:flyy_flutter_plugin_example/open-detail.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(userId: 'peter88',),
    );
  }
}

class MyApp extends StatefulWidget {

  MyApp({super.key,required this.userId});
  @override
  _MyAppState createState() => _MyAppState();

  String userId;
}

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

  late FlyyFlutterPlugin flyy;
  FlyyScreenTracking _flyyScreenTracking = FlyyScreenTracking();

  var pollIdController = TextEditingController();
  var surveyIdController = TextEditingController();
  var quizIdController = TextEditingController();

  @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.adityabirlacapitaldigital.OneApp");
    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('#C7222A', '#C7222A');
    //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(widget.userId);
    FlyyFlutterPlugin.setFlyyUserName(widget.userId);
    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: SingleChildScrollView(
          child: Column(
            children: [
              GestureDetector(
                onTap: () async {
                  // var data = await FlyyFlutterPlugin.verifyProductCode("057F2BN~1747919722~FIN-ILP-2025-01");
                  //  print(data);

                  FlyyFlutterPlugin.openFlyyOffersPage();
                                     
                  //FlyyFlutterPlugin.setReferralHistoryInfoMessage("Testing text...");
                  // FlyyFlutterPlugin.setReferralHistoryMessage("You've earned the maximum reward of 500 ABCD coins!");
                  //FlyyFlutterPlugin.openFlyyInviteAndEarnQR(19946);
                  //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.setInviteesHide(true);
                  // FlyyFlutterPlugin.listenFlyySDKClosed();
                  FlyyFlutterPlugin.openFlyyInviteAndEarnQR(0);
                },
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Center(
                    child: Text('Invite And Earn QR'),
                  ),
                ),
              ),
              GestureDetector(
                onTap: () {
                  FlyyFlutterPlugin.openFlyyWalletPage();
                  // FlyyFlutterPlugin.openFlyyReferralsPage();
                },
                child: Padding(
                  padding: const EdgeInsets.all(20.0),
                  child: Center(
                    child: Text('Start Wallet Page'),
                  ),
                ),
              ),
              SizedBox(
                height: 20,
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xfffff4e4),
                    borderRadius: new BorderRadius.circular(10.0),
                  ),
                  child: Padding(
                      padding: EdgeInsets.only(left: 15, right: 15, top: 5),
                    child: TextFormField(
                      keyboardType: TextInputType.number,
                      controller: pollIdController,
                      decoration: InputDecoration(
                        border: InputBorder.none,
                        labelText: "Poll Id"
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 10,
              ),
              ElevatedButton(
                  onPressed:(){
                    // Navigator.of(context).push(
                    //   MaterialPageRoute(builder: (context) => OpenDetailWidget(campaignId: int.parse(pollIdController.text), screenType: "poll")),
                    // );
                  },
                  child: Text("Poll",style: TextStyle(color: Colors.green),)),
              SizedBox(
                height: 20,
              ),
              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xfffff4e4),
                    borderRadius: new BorderRadius.circular(10.0),
                  ),
                  child: Padding(
                    padding: EdgeInsets.only(left: 15, right: 15, top: 5),
                    child: TextFormField(
                      keyboardType: TextInputType.number,
                      controller: surveyIdController,
                      decoration: InputDecoration(
                          border: InputBorder.none,
                          labelText: "Survey Id"
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 10,
              ),
              ElevatedButton(
                  onPressed:(){
                    // Navigator.of(context).push(
                    //   MaterialPageRoute(builder: (context) => OpenDetailWidget(campaignId: int.parse(surveyIdController.text), screenType: "survey")),
                    // );
                  },
                  child: Text("Survey",style: TextStyle(color: Colors.green),)),

              SizedBox(
                height: 20,
              ),

              Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: Container(
                  decoration: BoxDecoration(
                    color: Color(0xfffff4e4),
                    borderRadius: new BorderRadius.circular(10.0),
                  ),
                  child: Padding(
                    padding: EdgeInsets.only(left: 15, right: 15, top: 5),
                    child: TextFormField(
                      keyboardType: TextInputType.number,
                      controller: quizIdController,
                      decoration: InputDecoration(
                          border: InputBorder.none,
                          labelText: "Quiz Id"
                      ),
                    ),
                  ),
                ),
              ),
              SizedBox(
                height: 10,
              ),
              ElevatedButton(
                  onPressed:(){
                    // Navigator.of(context).push(
                    //   MaterialPageRoute(builder: (context) => OpenDetailWidget(campaignId: int.parse(quizIdController.text), screenType: "quiz")),
                    // );
                  },
                  child: Text("Quiz",style: TextStyle(color: Colors.green),)),
              // Container(
              //   height: 155,
              //   child: FlyyStories(),
              // )
              // FlyyFlutterPlugin.flyyWidget()
              // FlyyCustomCheckInView(),
            /*  Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: FlyySurveyWidget(gameId: 848,paddingLeft: 20,paddingRight: 20,fontFamilyCustom: "PlaywriteIN",),
              )*/
              /*Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: FlyyPollWidget(gameId: 849,fontFamilyCustom: "PlaywriteIN"),
              )*/
             /* Padding(
                padding: const EdgeInsets.symmetric(horizontal: 20),
                child: FlyyQuizWidget(gameId: 4220),
              )*/
              // FlyyPollWidget(gameId: 838),
              // FlyyPollWidget(gameId: 840),
            ],
          ),
        ),
      ),
    );
  }
}
5
likes
0
points
1.49k
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter wrapper around our Android and iOS mobile SDKs

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

dio, dotted_line, eventify, flutter, html, shared_preferences, url_launcher

More

Packages that depend on flyy_flutter_plugin

Packages that implement flyy_flutter_plugin