post.dart 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import 'attachment.dart';
  2. class Post {
  3. final String added;
  4. final List<Attachment> attachments;
  5. final String content;
  6. final String edited;
  7. final String id;
  8. final String published;
  9. final String service;
  10. final String title;
  11. final String user;
  12. final String baseUrl;
  13. Post({
  14. required this.added,
  15. required this.attachments,
  16. required this.content,
  17. required this.edited,
  18. required this.id,
  19. required this.published,
  20. required this.service,
  21. required this.title,
  22. required this.user,
  23. required this.baseUrl,
  24. });
  25. List<Attachment> get mediaAttachments =>
  26. attachments.where((a) => a.isImage || a.isVideo).toList();
  27. factory Post.fromJson(Map<String, dynamic> json, String baseUrl) => Post(
  28. added: json['added'],
  29. attachments: List<Attachment>.from(
  30. json['attachments'].map((x) => Attachment.fromJson(x,baseUrl))),
  31. content: json['content'],
  32. edited: json['edited'] ?? "",
  33. id: json['id'],
  34. published: json['published'],
  35. service: json['service'],
  36. title: json['title'],
  37. user: json['user'],
  38. baseUrl: baseUrl,
  39. );
  40. }