FirebaseNotificationsHandler class

Wrap this widget on the MaterialApp to enable receiving notifications.

Inheritance

Constructors

FirebaseNotificationsHandler({Key? key, String? vapidKey, bool enableLogs = true, void onTap(GlobalKey<NavigatorState> navigatorKey, AppState appState, Map payload)?, void onFCMTokenInitialize(BuildContext, String?)?, void onFCMTokenUpdate(BuildContext, String?)?, void onOpenNotificationArrive(GlobalKey<NavigatorState> navigatorKey, Map payload)?, GlobalKey<NavigatorState>? defaultNavigatorKey, String? customSound, int notificationIdCallback(RemoteMessage)?, bool handleInitialMessage = true, String channelId = Constants.channelId, String channelName = Constants.channelName, String channelDescription = Constants.channelDescription, String? groupKey, required Widget child})
const

Properties

channelDescription String
The notification channel's description. Defaults to 'Notifications'.
final
channelId String
If message.notification?.android?.channelId exists in the map, then it is used, if not then the default value is used, else the value passed will be used.
final
channelName String
The notification channel's name. Defaults to 'Notifications'.
final
child Widget
The child of the widget. Typically a MaterialApp.
final
customSound String?
Pass in the name of the audio file as a string if you want a custom sound for the notification.
final
defaultNavigatorKey GlobalKey<NavigatorState>?
If you have a navigator key initialized in your app, then pass the key here, this will be sent back in the onTap callback which can be used to see the currentState of the navigator, current context etc.
final
enableLogs bool
Whether to enable logs on certain events like new notification or fcmToken updates etc.
final
groupKey String?
Specifies the group that this notification belongs to.
final
handleInitialMessage bool
Whether to check if the application has been opened from a terminated state via a RemoteMessage.
final
hashCode int
The hash code for this object.
no setterinherited
key Key?
Controls how one widget replaces another widget in the tree.
finalinherited
notificationIdCallback → (int Function(RemoteMessage)?)
Can be passed to modify the id used by the local notification when app is in foreground
final
onFCMTokenInitialize → (void Function(BuildContext, String?)?)
This callback is triggered when the fcmToken initializes.
final
onFCMTokenUpdate → (void Function(BuildContext, String?)?)
This callback is triggered when the fcmToken updates.
final
onOpenNotificationArrive → (void Function(GlobalKey<NavigatorState> navigatorKey, Map payload)?)
This callback is triggered when the a new notification arrives when the app is open i.e. appState is AppState.open.
final
onTap → (void Function(GlobalKey<NavigatorState> navigatorKey, AppState appState, Map payload)?)
This callback is triggered when the notification is tapped. It provides 3 values namely:
final
runtimeType Type
A representation of the runtime type of the object.
no setterinherited
vapidKey String?
On web, a vapidKey is required to fetch the default FCM token for the device. The fcm token can be accessed from the onFCMTokenInitialize or onFCMTokenUpdate callbacks.
final

Methods

createElement() StatefulElement
Creates a StatefulElement to manage this widget's location in the tree.
inherited
createState() → _FirebaseNotificationsHandlerState
Creates the mutable state for this widget at a given location in the tree.
override
debugDescribeChildren() List<DiagnosticsNode>
Returns a list of DiagnosticsNode objects describing this node's children.
inherited
debugFillProperties(DiagnosticPropertiesBuilder properties) → void
Add additional properties associated with the node.
inherited
noSuchMethod(Invocation invocation) → dynamic
Invoked when a nonexistent method or property is accessed.
inherited
toDiagnosticsNode({String? name, DiagnosticsTreeStyle? style}) DiagnosticsNode
Returns a debug representation of the object that is used by debugging tools and by DiagnosticsNode.toStringDeep.
inherited
toString({DiagnosticLevel minLevel = DiagnosticLevel.info}) String
A string representation of this object.
inherited
toStringDeep({String prefixLineOne = '', String? prefixOtherLines, DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a string representation of this node and its descendants.
inherited
toStringShallow({String joiner = ', ', DiagnosticLevel minLevel = DiagnosticLevel.debug}) String
Returns a one-line detailed description of the object.
inherited
toStringShort() String
A short, textual description of this widget.
inherited

Operators

operator ==(Object other) bool
The equality operator.
inherited

Static Properties

fcmToken String?
Firebase messaging token
no setter
Default GlobalKey navigator of type NavigatorState.
no setter
onFCMTokenRefresh Stream<String>
final
openedAppFromNotification bool
A boolean that can be used to see whether the app was initially opened from a notification.
no setter

Static Methods

sendNotification({required String cloudMessagingServerKey, required String title, required List<String> fcmTokens, String? body, String? imageUrl, Map? payload, Map? additionalHeaders, Map? notificationMeta}) Future<Response>
Trigger FCM notification.

Constants

initializeFCMToken → const Future<String?> Function({bool log = true, String? vapidKey})