initFirebase static method

dynamic initFirebase({
  1. FirebaseOptions? options,
  2. dynamic onMessage(
    1. RemoteMessage message
    )?,
  3. dynamic onMessageOpenedApp(
    1. RemoteMessage message
    )?,
})

Implementation

static initFirebase({
  FirebaseOptions? options,
  Function(RemoteMessage message)? onMessage,
  Function(RemoteMessage message)? onMessageOpenedApp,
}) async {
  await Firebase.initializeApp(
    options: options,
  );
  FirebaseMessaging messaging = FirebaseMessaging.instance;

  await messaging.requestPermission(
    alert: true,
    announcement: false,
    badge: true,
    carPlay: false,
    criticalAlert: false,
    provisional: false,
    sound: true,
  );

  FirebaseMessaging.onBackgroundMessage(firebaseMessagingBackgroundHandler);

  FirebaseMessaging.onMessage.listen((RemoteMessage message) {
    handleNotification(message);
    if (onMessage != null) {
      onMessage(message);
    }
  });
  FirebaseMessaging.onMessageOpenedApp.listen((message) {
    if (onMessageOpenedApp != null) {
      onMessageOpenedApp(message);
    }
  });
}