initializeNotificationService static method
Implementation
static Future<String?> initializeNotificationService({
void Function(RemoteMessage remoteMessage)?
onPushBackgroundNotificationOpened,
void Function(NotificationResponse notificationResponse)?
onLocalForegroundNotificationOpened,
void Function(NotificationResponse notificationResponse)?
onLocalBackgroundNotificationOpened,
}) async {
await requestPermission();
const InitializationSettings initializationSettings =
InitializationSettings(
android: AndroidInitializationSettings(
'@drawable/ic_notification',
),
iOS: DarwinInitializationSettings(),
);
await flutterLocalNotificationsPlugin.initialize(
initializationSettings,
onDidReceiveNotificationResponse: onLocalForegroundNotificationOpened,
onDidReceiveBackgroundNotificationResponse:
onLocalForegroundNotificationOpened,
);
firebaseMessaging.setForegroundNotificationPresentationOptions(
alert: true,
badge: true,
sound: true,
);
token = await firebaseMessaging.getToken();
FirebaseMessaging.onMessage.listen(_onForegroundMessageHandler);
FirebaseMessaging.onBackgroundMessage(_onBackgroundMessageHandler);
FirebaseMessaging.onMessageOpenedApp
.listen(onPushBackgroundNotificationOpened);
return token;
}