initialize method

Future<void> initialize({
  1. bool enableNotifications = true,
})

Restores the queue of UserTasks from persistent storage.

Also starts the hourly check for expired tasks.

If enableNotifications is true, a notification is shown when a task is enqueued.

Called by SmartPhoneClientManager.configure.

Implementation

Future<void> initialize({bool enableNotifications = true}) async {
  _notificationsEnabled = enableNotifications;

  // Restore previous queue from persistent storage.
  await _restoreQueue();

  // set up a timer which expires tasks in the queue once an hour
  _garbageCollector = Timer.periodic(const Duration(hours: 1), (_) {
    for (var task in userTasks) {
      if (task.expiresIn?.isNegative ?? false) expire(task.id);
    }
  });
}