Closed jacovdbosch closed 3 years ago
Thanks for the bug report, this is exactly what customParser
was meant for, but it seems this is not working as intended.
As a workaround you can still access unsupported properties in their text-representation by calling VComponent.getProperty()
, e.g. in your case:
final id = calendar.getProperty<TextProperty>('X-CALENDAR-ID')?.text;
Yes, thanks for picking this up. When I use the given solution, I get type 'Property' is not a subtype of type 'TextProperty?' in type cast
. This might be because I do not have null-safety turned on however, but I do not know for sure. It does seem to work with
final id = event.getProperty('X-CALENDAR-ID')?.textValue;
So I will be using that for now.
Sorry, you are right of course - without knowing the property, it will always be the generic Property
and not TextProperty
that will be generated. So your code is correct.
This is now released as v 0.10.0
What is X-CALENDAR-ID
used for and is it always a numeric value?
Usage example:
test('Calendar simple', () {
final text = '''BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//hacksw/handcal//NONSGML v1.0//EN
X-XXX-NUMBER:123
BEGIN:VEVENT
UID:19970610T172345Z-AF23B2@example.com
DTSTAMP:19970610T172345Z
DTSTART:19970714T170000Z
DTEND:19970715T040000Z
SUMMARY:Bastille Day Party
END:VEVENT
END:VCALENDAR''';
// final calendar = VComponent.parse(text);
final calendar = VComponent.parse(text, customParser: (name, definition) {
if (name == 'X-XXX-NUMBER') {
return IntegerProperty(definition);
}
});
expect(calendar, isInstanceOf<VCalendar>());
expect(calendar.children, isNotEmpty);
expect(
calendar.getProperty('X-XXX-NUMBER'), isInstanceOf<IntegerProperty>());
expect(
calendar.getProperty<IntegerProperty>('X-XXX-NUMBER')?.intValue, 123);
});
This is now released as v 0.10.0
What is
X-CALENDAR-ID
used for and is it always a numeric value?
Yeah, I add it to the events, so I have a reference back to the original calendar, in this case it is an integer value. Thanks for fixing the bug.
I added a custom property, but I keep getting this error when adding the property to a component.
I tried to fix this by providing a custom parser on
VComponent.parse(ical, customParser: (name, definition) {})
, but this does not seem to get used. Is there any way to register properties without having to edit the code directly?