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

outdated

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.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;

  late FlyyFlutterPlugin flyy;

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

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

    //To set your package name same as entered in Flyy Dashboard
    FlyyFlutterPlugin.setDeeplinkPackage("<package_name>");
    FlyyFlutterPlugin.setPackageName("<package_name>");
    initFlyySdk();
    setupFirebase();
  }

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

  getWalletBalance() async {
    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);
    }
  }

  @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(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.PRODUCTION);

    FlyyFlutterPlugin.setThemeColor("#cc1d27", "#cc1d27");

    FlyyFlutterPlugin.setFlyyNewUser("<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();
                  },
                  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();
                  },
                  child: Padding(
                    padding: const EdgeInsets.all(20.0),
                    child: Center(
                      child: Text('Start Wallet Page'),
                    ),
                  ),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}
5
likes
0
points
989
downloads

Publisher

unverified uploader

Weekly Downloads

Flutter wrapper around our Android and iOS mobile SDKs

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

eventify, flutter

More

Packages that depend on flyy_flutter_plugin

Packages that implement flyy_flutter_plugin