initialize method
Initializes the Firebase Messaging service.
Implementation
@override
Future<void> initialize(
BuildContext context, {
IFastErrorReporter? errorReporter,
}) async {
_logger.debug('Initializing...');
final permission = await _getNotificationStatus();
_logger.info('Message notification permission', permission);
final bloc = FastAppPermissionsBloc.instance;
final event = FastAppPermissionsBlocEvent.updateNotificationPermission(
permission,
);
bloc.addEvent(event);
final blocState = await RaceStream([
bloc.onData.where((state) => state.notificationPermission == permission),
bloc.onError,
]).first;
if (blocState is! FastAppPermissionsBlocState) {
_logger.error('Failed to initialize: $blocState');
throw blocState;
}
FirebaseMessaging.onMessage.listen((RemoteMessage message) {
debugLog('Message received: ${message.data}', debugLabel: debugLabel);
// TODO: handle message
});
_logger.debug('Initialized');
}