initializeNotifications method
Initializes push notification system with permissions and handlers.
This method should be called during app initialization. It:
- Requests notification permissions from the user
- Initializes Firebase Messaging
- Registers the device token with the backend
- Sets up handlers for foreground and tap notifications
Parameters:
appId: Application identifier for backend registrationchannelName: 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();
}