RecurrenceRule.fromString constructor
RecurrenceRule.fromString(
- String rrule
Initialize a RecurrenceRule based on a rrule
string.
Implementation
factory RecurrenceRule.fromString(String rrule) {
var str = rrule.substring(rrule.indexOf('RRULE:') + 6);
var parameters = <String, String>{};
str.split(';').forEach((element) {
var par = element.split('=');
parameters[par[0]] = par[1];
});
var frequency = Frequency.DAILY;
for (var element in Frequency.values) {
if (element.name == parameters['FREQ']) frequency = element;
}
var end = End.never();
int interval = 1;
parameters.forEach((key, value) {
switch (key) {
case 'INTERVAL':
interval = int.tryParse(value) ?? 1;
break;
case 'UNTIL':
end = End.until(Duration(milliseconds: int.tryParse(value) ?? 1));
break;
case 'COUNT':
end = End.count(int.tryParse(value) ?? 1);
break;
default:
}
});
return RecurrenceRule(frequency, interval: interval, end: end);
}