smart_firebase_fcm 1.0.0 copy "smart_firebase_fcm: ^1.0.0" to clipboard
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

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

1
likes
0
points
332
downloads

Publisher

verified publisherquantumeye.in

Weekly Downloads

A plug-and-play modular Firebase FCM package with local notifications, redirection, and manual feature toggles (analytics, crashlytics, etc.).

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

firebase_analytics, firebase_core, firebase_crashlytics, firebase_messaging, flutter, flutter_local_notifications

More

Packages that depend on smart_firebase_fcm