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