periodicallyShow method

Future<void> periodicallyShow(
  1. int id,
  2. String? title,
  3. String? body,
  4. RepeatInterval repeatInterval,
  5. NotificationDetails notificationDetails, {
  6. String? payload,
  7. bool androidAllowWhileIdle = false,
})

Periodically show a notification using the specified interval.

For example, specifying a hourly interval means the first time the notification will be an hour after the method has been called and then every hour after that.

If androidAllowWhileIdle is false, the Android AlarmManager APIs are used to set a recurring inexact alarm that would present the notification. This means that there may be delay in on when notifications are displayed. If androidAllowWhileIdle is true, the Android AlarmManager APIs are used to schedule a single notification to be shown at the exact time even when the device is in a low-power idle mode. After it is shown, the next one would be scheduled and this would repeat.

Implementation

Future<void> periodicallyShow(
  int id,
  String? title,
  String? body,
  RepeatInterval repeatInterval,
  NotificationDetails notificationDetails, {
  String? payload,
  bool androidAllowWhileIdle = false,
}) async {
  if (kIsWeb) {
    return;
  }
  if (defaultTargetPlatform == TargetPlatform.android) {
    await resolvePlatformSpecificImplementation<
            AndroidFlutterLocalNotificationsPlugin>()
        ?.periodicallyShow(id, title, body, repeatInterval,
            notificationDetails: notificationDetails.android,
            payload: payload,
            androidAllowWhileIdle: androidAllowWhileIdle);
  } else if (defaultTargetPlatform == TargetPlatform.iOS) {
    await resolvePlatformSpecificImplementation<
            IOSFlutterLocalNotificationsPlugin>()
        ?.periodicallyShow(id, title, body, repeatInterval,
            notificationDetails: notificationDetails.iOS, payload: payload);
  } else if (defaultTargetPlatform == TargetPlatform.macOS) {
    await resolvePlatformSpecificImplementation<
            MacOSFlutterLocalNotificationsPlugin>()
        ?.periodicallyShow(id, title, body, repeatInterval,
            notificationDetails: notificationDetails.macOS, payload: payload);
  } else {
    await FlutterLocalNotificationsPlatform.instance
        .periodicallyShow(id, title, body, repeatInterval);
  }
}