smart_firebase_fcm 1.0.0
smart_firebase_fcm: ^1.0.0 copied to clipboard
A plug-and-play modular Firebase FCM package with local notifications, redirection, and manual feature toggles (analytics, crashlytics, etc.).
# ๐ smart_firebase_fcm
A plug-and-play Firebase FCM (Push Notification) package for Flutter โ with full support for foreground/background notifications, deep link redirection, local notifications, and manual toggles for Firebase Analytics and Crashlytics.
---
## โจ Features
- โ
One-line Firebase + FCM initialization
- โ
Foreground + background + terminated notification redirection
- โ
Foreground local notifications via `flutter_local_notifications`
- โ
Android notification channel configuration
- โ
Optional: Firebase Analytics and Crashlytics (enabled/disabled via flags)
- โ
Clean, modular code โ easy to extend
---
## ๐ Quick Start
### 1. Enable or disable Firebase features
```dart
import 'package:smart_firebase_fcm/smart_firebase_fcm.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
FirebaseFeatureFlags.enableAnalytics = false;
FirebaseFeatureFlags.enableCrashlytics = true;
FirebaseFeatureFlags.enableFCM = true;
await FCMInitializer.initialize(
onTap: FCMHandler.handleMessage,
);
runApp(const MyApp());
}
2. Handle redirection from notification tap #
void handleMessage(RemoteMessage message) {
final type = message.data['type'];
switch (type) {
case 'order':
// Navigate to order screen
break;
case 'chat':
// Navigate to chat screen
break;
default:
// Fallback or log unknown type
break;
}
}
3. Get the FCM device token #
final token = await FCMInitializer.getDeviceToken();
print("FCM Token: $token");
๐ฆ Installation #
Add to your pubspec.yaml:
dependencies:
smart_firebase_fcm: ^1.0.0
๐ง Notification Payload Structure (Recommended) #
Make sure your backend sends data payload for redirection:
{
"notification": {
"title": "New Order!",
"body": "You have a new order."
},
"data": {
"type": "order",
"order_id": "12345"
}
}
๐งฑ Under the Hood #
-
โ
Firebase.initializeApp()+ permission handling -
โ FCM listeners for:
onMessage(foreground)onMessageOpenedApp(background)getInitialMessage()(terminated)
-
โ Local notifications via
flutter_local_notifications -
โ Android notification channel setup
-
โ Feature flags to disable/enable:
- Firebase Analytics
- Firebase Crashlytics
- Firebase Messaging
๐งช Example App #
A working example is provided in the example/ folder.
cd example/
flutter run
โ FAQ #
Q: Will it work without Firebase Analytics or Crashlytics?
A: Yes! You can disable them individually using FirebaseFeatureFlags.
Q: Can I customize redirection behavior?
A: Absolutely. Modify the FCMHandler.handleMessage() function with your own navigation logic.
Q: Does this support iOS and Android? A: Yes, both are supported. Make sure you configure notification permissions on iOS correctly.
๐ License #
MIT License ยฉ 2025 Divyaraj Jadeja