@@ -82,6 +82,7 @@ class PushNotificationService {
8282 onTap,
8383 GlobalKey <NavigatorState >? navigatorKey,
8484 String ? customSound,
85+ required bool handleInitialMessage,
8586 required String channelId,
8687 required String channelName,
8788 required String channelDescription,
@@ -111,10 +112,12 @@ class PushNotificationService {
111112
112113 _fcmToken = await initializeFCMToken (vapidKey: vapidKey);
113114
114- final _bgMessage = await _fcm.getInitialMessage ();
115- if (_bgMessage != null ) {
116- _openedAppFromNotification = true ;
117- _onBackgroundMessage (_bgMessage);
115+ if (handleInitialMessage) {
116+ final bgMessage = await _fcm.getInitialMessage ();
117+ if (bgMessage != null ) {
118+ _openedAppFromNotification = true ;
119+ _onBackgroundMessage (bgMessage);
120+ }
118121 }
119122
120123 /// Registering the listeners
@@ -157,14 +160,14 @@ class PushNotificationService {
157160 /// notifications to show a notification when the app is in foreground.
158161 static Future <FlutterLocalNotificationsPlugin >
159162 _initializeLocalNotifications () async {
160- final _flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin ();
163+ final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin ();
161164 const initializationSettings = InitializationSettings (
162165 android: AndroidInitializationSettings ('@mipmap/ic_launcher' ),
163166 // iOS: IOSInitializationSettings(
164167 // onDidReceiveLocalNotification: (id, title, body, payload) async {},
165168 // ),
166169 );
167- await _flutterLocalNotificationsPlugin .initialize (
170+ await flutterLocalNotificationsPlugin .initialize (
168171 initializationSettings,
169172 onSelectNotification: (String ? payload) async {
170173 if (_onTap != null ) {
@@ -176,7 +179,7 @@ class PushNotificationService {
176179 }
177180 },
178181 );
179- return _flutterLocalNotificationsPlugin ;
182+ return flutterLocalNotificationsPlugin ;
180183 }
181184
182185 /// [_notificationHandler] implementation
@@ -225,7 +228,7 @@ class PushNotificationService {
225228 }
226229 }
227230
228- final _androidSpecifics = AndroidNotificationDetails (
231+ final androidSpecifics = AndroidNotificationDetails (
229232 message.notification? .android? .channelId ?? _channelId! ,
230233 _channelName! ,
231234 channelDescription: _channelDescription! ,
@@ -241,19 +244,19 @@ class PushNotificationService {
241244 enableVibration: true ,
242245 );
243246
244- final _iOsSpecifics = IOSNotificationDetails (sound: _customSound);
247+ final iOsSpecifics = IOSNotificationDetails (sound: _customSound);
245248
246249 final notificationPlatformSpecifics = NotificationDetails (
247- android: _androidSpecifics ,
248- iOS: _iOsSpecifics ,
250+ android: androidSpecifics ,
251+ iOS: iOsSpecifics ,
249252 );
250253
251- final _localNotifications = await _initializeLocalNotifications ();
254+ final localNotifications = await _initializeLocalNotifications ();
252255
253256 _notificationIdCallback ?? = (_) => DateTime .now ().hashCode;
254257
255258 if (appState == AppState .open) {
256- await _localNotifications .show (
259+ await localNotifications .show (
257260 _notificationIdCallback !(message),
258261 message.notification? .title,
259262 message.notification? .body,
0 commit comments