configure method

Future<SILFCM> configure({
  1. required BuildContext context,
  2. OnMessageCallback? callback,
})

configure is responsible for correctly setting up local notifications ( and asking for permission if needed) and wiring-up firebase messaging onMessage callback to show fcm messages

Implementation

Future<SILFCM> configure({
  required BuildContext context,
  OnMessageCallback? callback,
}) async {
  navigationCallback = callback;
  final TargetPlatform platform = Theme.of(context).platform;
  await this.initializeLocalNotifications();
  if (platform == TargetPlatform.iOS) {
    await requestIOSLocalNotificationsPermissions(
        localNotificationsPlugin: localNotificationsPlugin);
    final NotificationSettings settings =
        await this.requestIOSFCMMessagingPermission();
    if (settings.authorizationStatus != AuthorizationStatus.authorized) {
      // call callback
    }
  }

  // create high importance channel for android
  if (platform == TargetPlatform.android) {
    androidChannel = await createAndroidHighImportanceChannel(
        localNotificationsPlugin: localNotificationsPlugin);
  }

  // setup device token
  await this.getDeviceToken();

  // enabling foreground notifications so that they can be visible while the app is in the foreground
  await firebaseMessaging.setForegroundNotificationPresentationOptions(
    alert: true, // Required to display a heads up notification
    badge: true,
    sound: true,
  );

  onMessageSetup(context: context, callback: callback);

  return Future<SILFCM>.value(this);
}