oneShot static method

Future<bool> oneShot(
  1. Duration delay,
  2. int id,
  3. Function callback, {
  4. bool alarmClock = false,
  5. bool allowWhileIdle = false,
  6. bool exact = false,
  7. bool wakeup = false,
  8. bool rescheduleOnReboot = false,
})

Schedules a one-shot timer to run callback after time delay.

The callback will run whether or not the main application is running or in the foreground. It will run in the Isolate owned by the AndroidAlarmManager service.

callback must be either a top-level function or a static method from a class.

callback can be Function() or Function(int)

The timer is uniquely identified by id. Calling this function again with the same id will cancel and replace the existing timer.

id will passed to callback if it is of type Function(int)

If alarmClock is passed as true, the timer will be created with Android's AlarmManagerCompat.setAlarmClock.

If allowWhileIdle is passed as true, the timer will be created with Android's AlarmManagerCompat.setExactAndAllowWhileIdle or AlarmManagerCompat.setAndAllowWhileIdle.

If exact is passed as true, the timer will be created with Android's AlarmManagerCompat.setExact. When exact is false (the default), the timer will be created with AlarmManager.set.

If wakeup is passed as true, the device will be woken up when the alarm fires. If wakeup is false (the default), the device will not be woken up to service the alarm.

If rescheduleOnReboot is passed as true, the alarm will be persisted across reboots. If rescheduleOnReboot is false (the default), the alarm will not be rescheduled after a reboot and will not be executed.

Returns a Future that resolves to true on success and false on failure.

Implementation

static Future<bool> oneShot(
  Duration delay,
  int id,
  Function callback, {
  bool alarmClock = false,
  bool allowWhileIdle = false,
  bool exact = false,
  bool wakeup = false,
  bool rescheduleOnReboot = false,
}) =>
    oneShotAt(
      _now().add(delay),
      id,
      callback,
      alarmClock: alarmClock,
      allowWhileIdle: allowWhileIdle,
      exact: exact,
      wakeup: wakeup,
      rescheduleOnReboot: rescheduleOnReboot,
    );