initializeNotifications method

Future<void> initializeNotifications({
  1. required String appId,
  2. String? channelName,
})

Initializes push notification system with permissions and handlers.

This method should be called during app initialization. It:

  1. Requests notification permissions from the user
  2. Initializes Firebase Messaging
  3. Registers the device token with the backend
  4. Sets up handlers for foreground and tap notifications

Parameters:

  • appId: Application identifier for backend registration
  • channelName: Optional notification channel name for Android

Example:

await pushNotificationBloc.initializeNotifications(
  appId: 'my_app',
  channelName: 'General Notifications',
);

Implementation

Future<void> initializeNotifications({
  required String appId,
  String? channelName,
}) async {
  if (!await hasNotificationPermission()) {
    await requestNotificationPermission();
  }

  await _initializeFirebaseMessaging();
  await registerDeviceToken(appId);

  _setForegroundMessageHandler();
  _setNotificationOpenAppHandler();
}