easy_fcm 0.0.1
easy_fcm: ^0.0.1 copied to clipboard
The easiest way to handle Firebase Notifications in Flutter. Auto-handles foreground pop-ups and channels.
EasyFCM π #
A Logic-First wrapper for Firebase Messaging. Handle Foreground, Background, and Terminated notifications with one simple initialization.
π Why use EasyFCM? #
- Foreground Notifications: Automatically bridges Firebase to Local Notifications so users see a pop-up alert even when the app is open.
- Zero Boilerplate: No need to manually create Android Notification Channels or Request Permissions.
- Unified Logic: One callback (
onTap) handles notification taps from any state (Background, Terminated, or Foreground). - No Widget Wrapping: Pure Dart class. Initialize it in
main(),GetX,Provider, orBloc.
π¦ Installation #
Add this to your pubspec.yaml:
dependencies:
easy_fcm: ^0.0.1
π Usage #
1. Configure Firebase #
Run the standard FlutterFire command to generate your options file:
flutterfire configure
2. Initialize in main.dart #
import 'package:flutter/material.dart';
import 'package:easy_fcm/easy_fcm.dart';
import 'firebase_options.dart'; // Generated by flutterfire
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await EasyFCM().initialize(
// 1. Pass your generated Firebase Options
firebaseOptions: DefaultFirebaseOptions.currentPlatform,
// 2. Get the FCM Token (Send this to your backend)
onTokenReceived: (token) {
print("FCM Token: $token");
},
// 3. Handle Notification Taps
onTap: (message) {
print("Notification Tapped! Payload: ${message.data}");
// Example: Navigator.pushNamed(context, '/notifications');
},
);
runApp(const MyApp());
}
π± Platform Specific Setup #
Android #
To prevent build errors with local notifications, you must enable Core Library Desugaring in your android/app/build.gradle file.
- Open android/app/build.gradle.
- Update the android block and dependencies block as shown below:
android {
defaultConfig {
minSdkVersion 23
multiDexEnabled true
}
compileOptions {
versions
isCoreLibraryDesugaringEnabled true
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
}
dependencies {
coreLibraryDesugaring 'com.android.tools:desugar_jdk_libs:2.0.4'
}
iOS #
- Open your project in Xcode.
- Go to Signing & Capabilities.
- Add Push Notifications.
- Add Background Modes -> Check Remote notifications.
- Ensure your APNs Key is uploaded to the Firebase Console.