11import 'dart:convert' ;
2- import 'dart:io' ;
32
43import 'package:firebase_messaging/firebase_messaging.dart' ;
54import 'package:firebase_notifications_handler/src/app_state.dart' ;
65import 'package:firebase_notifications_handler/src/constants.dart' ;
76import 'package:firebase_notifications_handler/src/image_downloader.dart' ;
87import 'package:flutter/cupertino.dart'
98 show GlobalKey, NavigatorState, debugPrint;
10- import 'package:flutter/foundation.dart' show kIsWeb;
119import 'package:flutter_local_notifications/flutter_local_notifications.dart' ;
1210
1311/// Internal implementation class
@@ -58,7 +56,7 @@ class PushNotificationService {
5856 /// {@macro openedAppFromNotification}
5957 static bool _openedAppFromNotification = false ;
6058
61- /// [_openedAppFromNotification] getter.
59+ /// {@macro openedAppFromNotification}
6260 static bool get openedAppFromNotification => _openedAppFromNotification;
6361
6462 /// {@macro notificationIdCallback}
@@ -107,8 +105,7 @@ class PushNotificationService {
107105
108106 if (navigatorKey != null ) _navigatorKey = navigatorKey;
109107
110- /// Required only for iOS
111- if (! kIsWeb && Platform .isIOS) await _fcm.requestPermission ();
108+ await _fcm.requestPermission ();
112109
113110 _fcmToken = await initializeFCMToken (vapidKey: vapidKey);
114111
@@ -163,13 +160,13 @@ class PushNotificationService {
163160 final flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin ();
164161 const initializationSettings = InitializationSettings (
165162 android: AndroidInitializationSettings ('@mipmap/ic_launcher' ),
166- // iOS: IOSInitializationSettings(
167- // onDidReceiveLocalNotification: (id, title, body, payload) async {},
168- // ),
163+ iOS: DarwinInitializationSettings (),
169164 );
170165 await flutterLocalNotificationsPlugin.initialize (
171166 initializationSettings,
172- onSelectNotification: (String ? payload) async {
167+ onDidReceiveNotificationResponse: (details) {
168+ final payload = details.payload;
169+
173170 if (_onTap != null ) {
174171 _onTap !(
175172 navigatorKey,
@@ -179,13 +176,14 @@ class PushNotificationService {
179176 }
180177 },
181178 );
179+
182180 return flutterLocalNotificationsPlugin;
183181 }
184182
185183 /// [_notificationHandler] implementation
186184 static Future <void > _notificationHandler (
187185 RemoteMessage message, {
188- AppState ? appState,
186+ required AppState appState,
189187 }) async {
190188 _enableLogs ?? = Constants .enableLogs;
191189 if (_enableLogs! ) {
@@ -244,7 +242,7 @@ class PushNotificationService {
244242 enableVibration: true ,
245243 );
246244
247- final iOsSpecifics = IOSNotificationDetails (sound: _customSound);
245+ final iOsSpecifics = DarwinNotificationDetails (sound: _customSound);
248246
249247 final notificationPlatformSpecifics = NotificationDetails (
250248 android: androidSpecifics,
@@ -263,6 +261,7 @@ class PushNotificationService {
263261 notificationPlatformSpecifics,
264262 payload: jsonEncode (message.data),
265263 );
264+
266265 if (_onOpenNotificationArrive != null ) {
267266 _onOpenNotificationArrive !(_navigatorKey, message.data);
268267 }
@@ -271,7 +270,7 @@ class PushNotificationService {
271270 /// if AppState is open, do not handle onTap here because it will trigger as soon as
272271 /// notification arrives, instead handle in initialize method in onSelectNotification callback.
273272 else if (_onTap != null ) {
274- _onTap !(_navigatorKey, appState! , message.data);
273+ _onTap !(_navigatorKey, appState, message.data);
275274 }
276275 }
277276}
0 commit comments