taskOnceAfterDate static method

dynamic taskOnceAfterDate(
  1. String name,
  2. dynamic callback(), {
  3. required DateTime date,
})

Run a task after date Provide a name for the function and a callback to execute. The function will execute after the date provided. Example:

NyScheduler.taskAfterDate("myFunction", () {
  print("This will execute after the date");
}, date: DateTime.now().add(Duration(days: 1)));

The above example will execute after the date provided.

Implementation

static taskOnceAfterDate(String name, Function() callback,
    {required DateTime date}) async {
  /// Check if the date is in the past
  if (!date.isInPast()) {
    return;
  }
  String key = "${name}_after_date_$date";

  /// Check if we have already executed the task
  String keyExecuted = "${key}_executed";
  bool alreadyExecuted = await readBool(keyExecuted);

  if (!alreadyExecuted) {
    await writeBool(keyExecuted, true);
    await callback();
  }
}