periodicallyShowWithDuration method

Future<void> periodicallyShowWithDuration({
  1. required int id,
  2. required Duration repeatDurationInterval,
  3. required NotificationDetails notificationDetails,
  4. String? title,
  5. String? body,
  6. AndroidScheduleMode androidScheduleMode = AndroidScheduleMode.exact,
  7. String? payload,
})

Periodically show a notification using the specified custom duration interval.

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

On Android, this will also require additional setup for the app, especially in the app's AndroidManifest.xml file. Please see check the readme for further details.

Implementation

Future<void> periodicallyShowWithDuration({
  required int id,
  required Duration repeatDurationInterval,
  required NotificationDetails notificationDetails,
  String? title,
  String? body,
  AndroidScheduleMode androidScheduleMode = AndroidScheduleMode.exact,
  String? payload,
}) async {
  if (kIsWeb) {
    return;
  }
  if (defaultTargetPlatform == TargetPlatform.android) {
    await resolvePlatformSpecificImplementation<
          AndroidFlutterLocalNotificationsPlugin
        >()
        ?.periodicallyShowWithDuration(
          id: id,
          title: title,
          body: body,
          repeatDurationInterval: repeatDurationInterval,
          notificationDetails: notificationDetails.android,
          payload: payload,
          scheduleMode: androidScheduleMode,
        );
  } else if (defaultTargetPlatform == TargetPlatform.iOS) {
    await resolvePlatformSpecificImplementation<
          IOSFlutterLocalNotificationsPlugin
        >()
        ?.periodicallyShowWithDuration(
          id: id,
          title: title,
          body: body,
          repeatDurationInterval: repeatDurationInterval,
          notificationDetails: notificationDetails.iOS,
          payload: payload,
        );
  } else if (defaultTargetPlatform == TargetPlatform.macOS) {
    await resolvePlatformSpecificImplementation<
          MacOSFlutterLocalNotificationsPlugin
        >()
        ?.periodicallyShowWithDuration(
          id: id,
          title: title,
          body: body,
          repeatDurationInterval: repeatDurationInterval,
          notificationDetails: notificationDetails.macOS,
          payload: payload,
        );
  } else {
    await FlutterLocalNotificationsPlatform.instance
        .periodicallyShowWithDuration(
          id: id,
          title: title,
          body: body,
          repeatDurationInterval: repeatDurationInterval,
        );
  }
}