schedulePeriodicTask static method

Future<bool> schedulePeriodicTask({
  1. required String taskId,
  2. required Duration frequency,
  3. Map<String, dynamic> data = const {},
  4. bool requiresCharging = false,
  5. bool requiresNetwork = true,
})

Schedules a periodic background task with native OS task schedulers.

Returns true if successfully scheduled, false if unsupported or rejected by host OS.

Example:

final scheduled = await BloomBackground.schedulePeriodicTask(
  taskId: 'syncTasks',
  frequency: const Duration(minutes: 15),
  requiresNetwork: true,
  requiresCharging: false,
);

Implementation

static Future<bool> schedulePeriodicTask({
  required String taskId,
  required Duration frequency,
  Map<String, dynamic> data = const {},
  bool requiresCharging = false,
  bool requiresNetwork = true,
}) async {
  logger.info('BloomBackground: Scheduling periodic task "$taskId" every ${frequency.inMinutes}m');
  try {
    final res = await _channel.invokeMethod<bool>('schedulePeriodicTask', {
      'taskId': taskId,
      'frequencyMinutes': frequency.inMinutes,
      'data': data,
      'requiresCharging': requiresCharging,
      'requiresNetwork': requiresNetwork,
    });
    return res ?? false;
  } catch (e) {
    logger.warn('BloomBackground: Periodic task scheduling not supported on this platform: $e');
    return false;
  }
}