firebase_cloud_messaging_interop 1.2.0 copy "firebase_cloud_messaging_interop: ^1.2.0" to clipboard
firebase_cloud_messaging_interop: ^1.2.0 copied to clipboard

outdated

A dart plugin to use the Firebase Cloud Messaging Api (JS). You can retrieve the user's FCM token, delete it, access the notification data, ...

example/firebase_cloud_messaging_interop_example.dart

import 'package:firebase_cloud_messaging_interop/firebase_cloud_messaging_interop.dart';
import 'dart:html';

class FCMService {
  FCM fcm;

  String currentToken;

  FCMService() {
    fcm = FCM(publicVapidKey: "YourPublicVapidKey");

    fcm.onMessage((e) {
      /// You can access title, body and tag
    });

    fcm.onTokenRefresh(requestPermissionAndGetToken);
  }

  void requestPermissionAndGetToken() {
    Notification.requestPermission().then((permission) {
      if (permission == 'granted') {
        fcm.getToken().then((e) {
          currentToken = e;

          /// SEND TOKEN TO THE BACKEND SERVER
        });
      } else {
        /// The user doesn't want notification :(
      }
    });
  }

  void deleteCurrentToken() => fcm.deleteToken(currentToken);
}
15
likes
0
pub points
67%
popularity

Publisher

verified publishergaspardmerten.dev

A dart plugin to use the Firebase Cloud Messaging Api (JS). You can retrieve the user's FCM token, delete it, access the notification data, ...

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

js

More

Packages that depend on firebase_cloud_messaging_interop