post.dart 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  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. Post({
  13. required this.added,
  14. required this.attachments,
  15. required this.content,
  16. required this.edited,
  17. required this.id,
  18. required this.published,
  19. required this.service,
  20. required this.title,
  21. required this.user,
  22. });
  23. List<Attachment> get mediaAttachments =>
  24. attachments.where((a) => a.isImage || a.isVideo).toList();
  25. factory Post.fromJson(Map<String, dynamic> json, String baseUrl) => Post(
  26. added: json['added'],
  27. attachments: List<Attachment>.from(
  28. json['attachments'].map((x) => Attachment.fromJson(x,baseUrl))),
  29. content: json['content'],
  30. edited: json['edited'] ?? "",
  31. id: json['id'],
  32. published: json['published'],
  33. service: json['service'],
  34. title: json['title'],
  35. user: json['user'],
  36. );
  37. }