initialize method

  1. @override
Future<void> initialize()

Initialize push service, set all callbacks, must be called before using clickPayloads

Implementation

@override
Future<void> initialize() async {
  const initializationSettings = InitializationSettings(
    android: _initializationSettingsAndroid,
    iOS: _initializationSettingsDarwin,
  );

  await _localNotifications.initialize(
    initializationSettings,
    onDidReceiveNotificationResponse:
        (NotificationResponse notificationResponse) {
      switch (notificationResponse.notificationResponseType) {
        case NotificationResponseType.selectedNotification:
          final payload = notificationResponse.payload;
          if (payload != null) {
            clickPayloads.add(payload);
          }
        case NotificationResponseType.selectedNotificationAction:
          if (notificationResponse.actionId == _navigationActionId) {}
      }
    },
    onDidReceiveBackgroundNotificationResponse: _notificationTapBackground,
  );

  final launchPayload =
      (await _localNotifications.getNotificationAppLaunchDetails())
          ?.notificationResponse
          ?.payload;
  if (launchPayload != null) {
    clickPayloads.add(launchPayload);
  }

  tz.initializeTimeZones();
  final currentTimeZone = await FlutterTimezone.getLocalTimezone();
  tz.setLocalLocation(tz.getLocation(currentTimeZone));

  await _localNotifications.cancelAll();

  if (Platform.isAndroid) {
    final channels = [
      NormalPushConfig.channel,
      ScheduledPushConfig.channel,
      PeriodicPushConfig.channel,
    ];

    for (final channel in channels) {
      await _localNotifications
          .resolvePlatformSpecificImplementation<
              AndroidFlutterLocalNotificationsPlugin>()
          ?.createNotificationChannel(channel);
    }
  }
}