firebase_cloud_messaging_interop 2.0.1 copy "firebase_cloud_messaging_interop: ^2.0.1" to clipboard
firebase_cloud_messaging_interop: ^2.0.1 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';

class NotificationService {
  NotificationService() {
    // Direct init
    fcm = FirebaseMessagingWeb(publicVapidKey: 'YourPublicVapidKey');

    // Deferred init
    fcm = FirebaseMessagingWeb();
    fcm.init('YourPublicVapidKey');

    /// Setup callback for whenever a notification is received.
    /// The app must be open inside the navigator for this callback to fire.
    fcm.onMessage((Map notificationData) {
      // do something with notification data
    });

    /// Whenever the token is refreshed,
    fcm.onTokenRefresh(() async {
      final String token = await fcm.getToken();

      // push token to server
    });
  }

  FirebaseMessagingWeb fcm;

  String currentToken;

  /// Ask user for permission
  Future<bool> getPermission() => fcm.requestNotificationPermissions();

  /// Delete current user token
  void deleteCurrentToken() => fcm.deleteToken(currentToken);
}
15
likes
30
points
66
downloads

Publisher

verified publishergaspardmerten.dev

Weekly Downloads

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)

License

unknown (license)

Dependencies

js

More

Packages that depend on firebase_cloud_messaging_interop