Search packages, repositories and app categories

Package detailsv1.3.6

flutter_fcm

Flutter plugin for Firebase Cloud Messaging (FCM) , a cross-platform messaging solution that lets you reliably deliver messages on Android and iOS.

AndroidiOSmacOS
30-day downloads
177
Likes
41
Pub points
140

Install package

flutter pub add flutter_fcm

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

Flutter FCM is a Flutter plugin that enables cross-platform push notifications using Firebase Cloud Messaging (FCM) for Android, iOS, and macOS. It allows developers to reliably send messages, including notifications and data payloads, to users' devices. The plugin simplifies integration with FCM by providing straightforward APIs for handling token management, message reception, and background processing. It supports both foreground and background message delivery, making it ideal for real-time app updates and user engagement. Built for ease of use with Firebase, it streamlines the setup and management of push notifications across platforms.

Use cases

  • Sending real-time notifications
  • User engagement via push alerts
  • Background message handling
  • App state synchronization
  • Remote configuration updates

Key features

  • Cross-platform support (Android, iOS, macOS)
  • Token management utilities
  • Foreground and background message handling
  • Simple API for message reception
  • Integration with Firebase console

Suitable for

  • Apps requiring push notifications
  • Real-time messaging features
  • Firebase-integrated projects
  • Mobile apps targeting multiple platforms
  • User engagement campaigns

Considerations

  • Requires Firebase project setup
  • Needs proper permissions on each platform
  • Background execution limitations on iOS
  • Dependent on FCM server availability
  • Manual handling of notification display on some platforms

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

Firebase Messaging Plugin for Flutter

A Flutter plugin to use the Firebase Cloud Messaging API.

To learn more about Firebase Cloud Messaging, please visit the Firebase website

Getting Started

To get started with Firebase Cloud Messaging for Flutter, please see the documentation.

Why flutter_fcm?

  • 🚀 Easy to use
  • ❤ Supports local notification
  • 🛡️ Null safety
  • ⚡ On notification Received/Pressed works in all states: foreground,background and even when app is closed(not running)

Getting Started

To get started with Firebase Cloud Messaging for Flutter, see Android Installation. and iOS Installation.

Usage

The easiest way to use this library is via the top-level functions.


import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter_fcm/flutter_fcm.dart';

class Messaging {
  static String? token;

  static deleteToken() {
    Messaging.token = null;
    FCM.deleteRefreshToken();
  }
  static subscribeToTopic(String topic) {
    FCM.subscribeToTopic(topic);
  }
  static unsubscribeFromTopic(String topic) {
    FCM.unsubscribeFromTopic(topic);
  }

  @pragma('vm:entry-point')
  static Future<void> onNotificationReceived(RemoteMessage message) async {
    await Firebase.initializeApp();
    //print('Handling a message ${message}');

  }

  @pragma('vm:entry-point')
  static initFCM() async {
    try {
      await Firebase.initializeApp(
          options: DefaultFirebaseOptions.currentPlatform
      );
      await FCM.initializeFCM(
        withLocalNotification: true,
        // navigatorKey: Keys.navigatorKey,
        onNotificationReceived: onNotificationReceived,
        onNotificationPressed: (Map<String, dynamic> data) {

        },
        onTokenChanged: (String? token) {
          if (token != null) {
            //print('FCM token  $token');
            Messaging.token = token;


          }
        },
        // TODO add this icon to android/app/src/main/res/drawable/ic_launcher.png
        icon: 'ic_launcher',
      );
    } catch (e) {
      print(e);
    }
  }
}

Categories

Dependencies

Dependency list 3 items

Source repository

Projects using this package

No data available yet.