SchedulerConfig constructor

SchedulerConfig({
  1. required String eventKey,
  2. required TriggerType triggerType,
  3. int? triggerCount,
  4. DateTime? triggerTime,
  5. Duration? recurrenceInterval,
  6. int? recurrenceCount,
  7. RecurrenceType recurrenceType = RecurrenceType.none,
  8. int? maxRecurrences,
  9. DateTime? endTime,
  10. required VoidCallback onEvent,
  11. VoidCallback? recurrenceOnEvent,
  12. dynamic onStateUpdate(
    1. bool
    )?,
})

Creates a new scheduler configuration.

Throws assertions if required parameters are missing based on trigger type:

  • For count triggers: triggerCount must be provided
  • For time triggers: triggerTime must be provided
  • For count recurrence: recurrenceCount must be provided
  • For time recurrence: recurrenceInterval must be provided

Implementation

SchedulerConfig({
  required this.eventKey,
  required this.triggerType,
  this.triggerCount,
  this.triggerTime,
  this.recurrenceInterval,
  this.recurrenceCount,
  this.recurrenceType = RecurrenceType.none,
  this.maxRecurrences,
  this.endTime,
  required this.onEvent,
  this.recurrenceOnEvent,
  this.onStateUpdate,
}) {
  assert(
    triggerType == TriggerType.count
        ? triggerCount != null
        : triggerTime != null,
    'triggerCount must be provided when triggerType is count, triggerTime must be provided when triggerType is time',
  );

  assert(
    recurrenceType == RecurrenceType.none ||
        (recurrenceType == RecurrenceType.count && recurrenceCount != null) ||
        (recurrenceType == RecurrenceType.time && recurrenceInterval != null),
    'recurrenceCount must be provided when recurrenceType is count, recurrenceInterval must be provided when recurrenceType is time',
  );

  assert(
    triggerType == TriggerType.time
        ? (recurrenceInterval != null)
        : (triggerCount != null),
    'Time trigger requires recurrenceInterval, count trigger requires triggerCount',
  );
}