toJson method
Implementation
Map<String, dynamic> toJson() {
final data = <String, dynamic>{};
if (totalOccurrences != null) {
data[_totalOccurrencesKey] = totalOccurrences;
}
if (interval != null) {
data[_intervalKey] = interval;
}
if (endDate != null) {
data[_endDateKey] = endDate!.millisecondsSinceEpoch;
}
data[_recurrenceFrequencyKey] = recurrenceFrequency?.index;
if (daysOfWeek?.isNotEmpty == true) {
data[_daysOfWeekKey] = daysOfWeek!.map((d) => d.value).toList();
}
if (monthOfYear != null &&
recurrenceFrequency == RecurrenceFrequency.Yearly) {
data[_monthOfYearKey] = monthOfYear!.value;
}
if (recurrenceFrequency == RecurrenceFrequency.Monthly ||
recurrenceFrequency == RecurrenceFrequency.Yearly) {
if (weekOfMonth != null) {
data[_weekOfMonthKey] = weekOfMonth!.value;
} else {
// Days of the month should not be added to the recurrence parameter when WeekOfMonth is used
if (dayOfMonth != null) {
data[_dayOfMonthKey] = dayOfMonth;
}
}
}
return data;
}