SearchResultItem.fromXml constructor
SearchResultItem.fromXml(
- XmlElement xml
Parse one <item> element from the /search response.
Implementation
factory SearchResultItem.fromXml(XmlElement xml) {
final id = int.parse(xml.getAttribute('id')!);
final name = xml.getElement('name')?.getAttribute('value') ?? 'Unknown';
final type = xml.getAttribute('type');
final yearEl = xml.getElement('yearpublished');
final year = yearEl == null ? null : int.tryParse(yearEl.getAttribute('value')!);
final thumb = xml.getElement('thumbnail')?.innerText;
final img = xml.getElement('image')?.innerText;
return SearchResultItem(
id: id,
name: name,
type: type,
yearPublished: year,
thumbnailUrl: thumb,
imageUrl: img,
);
}