The Webfeed Flutter package for Appeto SDK.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 line
2.2 KiB

  1. import 'package:webfeed/domain/media/media.dart';
  2. import 'package:webfeed/domain/rss_category.dart';
  3. import 'package:webfeed/domain/rss_content.dart';
  4. import 'package:webfeed/domain/rss_source.dart';
  5. import 'package:webfeed/util/helpers.dart';
  6. import 'package:xml/xml.dart';
  7. class RssItem {
  8. final String title;
  9. final String description;
  10. final String link;
  11. final List<RssCategory> categories;
  12. final String guid;
  13. final String pubDate;
  14. final String author;
  15. final String comments;
  16. final RssSource source;
  17. final RssContent content;
  18. final Media media;
  19. RssItem({
  20. this.title,
  21. this.description,
  22. this.link,
  23. this.categories,
  24. this.guid,
  25. this.pubDate,
  26. this.author,
  27. this.comments,
  28. this.source,
  29. this.content,
  30. this.media,
  31. });
  32. factory RssItem.parse(XmlElement element) {
  33. var title = xmlGetString(element, "title", strict: false);
  34. var description = xmlGetString(element, "description", strict: false);
  35. var link = xmlGetString(element, "link", strict: false);
  36. var categories = element.findElements("category").map((element) {
  37. return new RssCategory.parse(element);
  38. }).toList();
  39. var guid = xmlGetString(element, "guid", strict: false);
  40. var pubDate = xmlGetString(element, "pubDate", strict: false);
  41. var author = xmlGetString(element, "author", strict: false);
  42. var comments = xmlGetString(element, "comments", strict: false);
  43. RssSource source;
  44. try {
  45. source = new RssSource.parse(element.findElements("source").first);
  46. } on StateError {}
  47. RssContent content;
  48. try {
  49. content =
  50. new RssContent.parse(element.findElements("content:encoded").first);
  51. } on StateError {}
  52. return new RssItem(
  53. title: title,
  54. description: description,
  55. link: link,
  56. categories: categories,
  57. guid: guid,
  58. pubDate: pubDate,
  59. author: author,
  60. comments: comments,
  61. source: source,
  62. content: content,
  63. media: Media.parse(element),
  64. );
  65. }
  66. @override
  67. String toString() {
  68. return '''
  69. title: $title
  70. description: $description
  71. link: $link
  72. guid: $guid
  73. pubDate: $pubDate
  74. author: $author
  75. comments: $comments
  76. source: $source
  77. content: $content
  78. ''';
  79. }
  80. }