The Webfeed Flutter package for Appeto SDK.
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

71 lignes
2.0 KiB

  1. import 'dart:core';
  2. import 'package:webfeedclient/domain/item.dart';
  3. import 'package:webfeedclient/util/helpers.dart';
  4. import 'package:xml/xml.dart';
  5. import 'image.dart';
  6. class Channel {
  7. final String title;
  8. final String description;
  9. final String link;
  10. final List<Item> items;
  11. final Image image;
  12. final String lastBuildDate;
  13. final String language;
  14. final String generator;
  15. final String copyright;
  16. Channel(this.title, this.description, this.link, this.items,
  17. {this.image, this.lastBuildDate, this.language, this.generator, this.copyright});
  18. factory Channel.parse(XmlDocument document) {
  19. XmlElement channelElement;
  20. try {
  21. channelElement = document
  22. .findAllElements("channel")
  23. .first;
  24. } on StateError {
  25. throw new ArgumentError("channel not found");
  26. }
  27. var title = xmlGetString(channelElement, "title");
  28. var description = xmlGetString(channelElement, "description");
  29. var link = xmlGetString(channelElement, "link");
  30. var feeds = channelElement.findAllElements("item").map((XmlElement element) {
  31. return new Item.parse(element);
  32. }).toList();
  33. Image image;
  34. try {
  35. image = new Image.parse(channelElement
  36. .findElements("image")
  37. .first);
  38. } on StateError {}
  39. var lastBuildDate = xmlGetString(channelElement, "lastBuildDate", strict: false);
  40. var language = xmlGetString(channelElement, "language", strict: false);
  41. var generator = xmlGetString(channelElement, "generator", strict: false);
  42. var copyright = xmlGetString(channelElement, "copyright", strict: false);
  43. return new Channel(title, description, link, feeds, image: image,
  44. lastBuildDate: lastBuildDate,
  45. language: language,
  46. generator: generator,
  47. copyright: copyright);
  48. }
  49. @override
  50. String toString() {
  51. return '''
  52. title: $title
  53. description: $description
  54. link: $link
  55. lastBuildDate: $lastBuildDate
  56. items: $items
  57. ''';
  58. }
  59. }