FLUTTER ECOSYSTEM

wh120/flutter_fcm

Firebase 클라우드 메시징(FCM) 플러터 패키지.

flutter_fcm 프로젝트 이미지
Stars
15
Forks
7
최근 푸시(UTC)
2025. 12. 15.
프로젝트 상태
활성
Wael Alhalabi GitHub avatar
GITHUB User

Wael Alhalabi ↗

Null
언어DartRubyPythonObjective-CJava

이 저장소가 배포한 패키지

사용 중인 의존성

의존성 목록 6 개

원본 README

아래는 영문 원문 스냅샷입니다. 최신 내용은 GitHub에서 확인하세요.

README 펼치기 / 접기

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);
    }
  }
}