Loading repository data…
Loading repository data…
rithik-dev / repository
An easy-to-use notifications handler for Firebase Notifications with built-in support for local notifications, allowing your app to display notifications even when it's in the foreground with no extra setup.
A transparent discovery signal based on current public GitHub metadata.
This score does not audit code, security, maintainers, documentation quality, or suitability. Verify the repository and its current documentation before adoption.
FirebaseNotificationsHandler is a simple and easy-to-use notifications handler for Firebase Notifications. It includes built-in support for local notifications, allowing your app to display notifications even when it's in the foreground with no extra setup. With customization options available, you can manage notification behavior seamlessly.
The package uses a widget-based approach, and exposes a widget to handle the notifications. This makes it feel like home for Flutter developers, as it integrates seamlessly with Flutter’s UI-driven architecture. With easy-to-use callbacks such as onTap, you can effortlessly manage and respond to notification taps and customize the notification behavior, providing a smooth integration process for any Flutter project.
| App In Foreground | App In Background | Expanded Notification |
|---|---|---|
onTap), when a notification arrives when app open (onOpenNotificationArrive), etc., making the widget simple to use.notificationTapsSubscription, notificationArrivesSubscription allowing listening to important notification events and managing them easily with the provided NotificationInfo objects.Several parameters and callbacks were renamed for clarity and consistency:
NotificationTapDetails is now NotificationInfo.onFCMTokenInitialize is now onFcmTokenInitialize.onFCMTokenUpdate is now onFcmTokenUpdate.initializeFCMToken is now initializeFcmToken.requestPermissionsOnInit is now requestPermissionsOnInitialize.AppState.closed is now AppState.terminated.navigatorKey parameter is no longer available in onTap and onOpenNotificationArrive. You’ll need to manage your own navigator key in your app. See the example app for more details on handling navigation.onFcmTokenInitialize and onFcmTokenUpdate no longer accept context. Ensure that any context-dependent logic is refactored.NotificationTapDetails has been renamed to NotificationInfo. This class now includes the firebaseMessage parameter, providing more comprehensive information.onTap and onOpenNotificationArrive now return a NotificationInfo object, replacing the previous payload. The payload can still be accessed using the payload property of NotificationInfo.notificationArrivesSubscription stream now returns NotificationInfo instead of just the payload.The configuration of local notifications has been refactored to use platform-specific getters in LocalNotificationsConfiguration:
channelId, channelName, and sound have been moved to localNotificationsConfiguration.androidConfig.sound have been moved to localNotificationsConfiguration.iosConfig.notificationIdGetter function is now also part of the LocalNotificationsConfiguration.onFCMTokenRefresh has been removed. Use onFcmTokenUpdate instead to handle token updates.sendFcmNotification has been deprecated for sending notifications from the client side. You'll now need to send notifications using Firebase Cloud Messaging (FCM) server-side APIs.sendLocalNotification function is introduced, which allows sending or scheduling local notifications.notificationTapsSubscription and notificationArrivesSubscription are available for handling notification taps and arrivals.permissionGetter, shouldHandleNotification, messageModifier, and stateKeyGetter are introduced for finer control over the notification lifecycle.getInitialMessage callback added for retrieving the initial notification that launched the app.For more details, refer to the CHANGELOG.
Create a Firebase project. Learn more about Firebase projects here.
Add your Android & iOS apps to your Firebase project and configure the Firebase the apps by following the setup instructions for Android and iOS separately.
Add firebase_core as a dependency in your pubspec.yaml file.
dependencies:
flutter:
sdk: flutter
firebase_core:
Call Firebase.initializeApp() in the main() method as shown to intialize Firebase in your project.
import 'package:firebase_core/firebase_core.dart';
void main() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);
runApp(MyApp());
}
[!NOTE] Refer to the platform specific setup for local notifications here
AndroidManifest.xml under the <application> tag:<!-- Can add a default notification channel (if not sending a channel id when sending notification) -->
<!-- If you don't specify a default channel id, and don't pass an id when sending notification, Android creates a default channel "Miscellaneous" -->
<meta-data
android:name="com.google.firebase.messaging.default_notification_channel_id"
android:value="default" />
<!-- Use the following tags if you need to different icons or color for app icon -->
<!-- <meta-data
android:name="com.google.firebase.messaging.default_notification_icon"
android:resource="@drawable/notification_icon" />
<meta-data
android:name="com.google.firebase.messaging.default_notification_color"
android:resource="@color/notification_color" /> -->
<intent-filter> in the <activity> tag:<intent-filter>
<action android:name="FLUTTER_NOTIFICATION_CLICK" />
<category android:name="android.intent.category.DEFAULT" />
</intent-filter>
[!NOTE] Refer to the platform specifi