|
| 1 | +import 'package:freezed_annotation/freezed_annotation.dart'; |
| 2 | + |
| 3 | +part 'models.freezed.dart'; |
| 4 | +part 'models.g.dart'; |
| 5 | + |
| 6 | +@freezed |
| 7 | +abstract class Author with _$Author { |
| 8 | + const factory Author({String? name, String? url, String? avatar}) = _Author; |
| 9 | + |
| 10 | + factory Author.fromJson(Map<String, dynamic> json) => _$AuthorFromJson(json); |
| 11 | +} |
| 12 | + |
| 13 | +@freezed |
| 14 | +abstract class Attachment with _$Attachment { |
| 15 | + const factory Attachment({ |
| 16 | + required String url, |
| 17 | + @JsonKey(name: 'mime_type') required String mimeType, |
| 18 | + String? title, |
| 19 | + @JsonKey(name: 'size_in_bytes') int? sizeInBytes, |
| 20 | + @JsonKey(name: 'duration_in_seconds') double? durationInSeconds, |
| 21 | + }) = _Attachment; |
| 22 | + |
| 23 | + factory Attachment.fromJson(Map<String, dynamic> json) => |
| 24 | + _$AttachmentFromJson(json); |
| 25 | +} |
| 26 | + |
| 27 | +@freezed |
| 28 | +abstract class Hub with _$Hub { |
| 29 | + const factory Hub({required String type, required String url}) = _Hub; |
| 30 | + |
| 31 | + factory Hub.fromJson(Map<String, dynamic> json) => _$HubFromJson(json); |
| 32 | +} |
| 33 | + |
| 34 | +@freezed |
| 35 | +abstract class Item with _$Item { |
| 36 | + const factory Item({ |
| 37 | + required String id, |
| 38 | + String? url, |
| 39 | + @JsonKey(name: 'external_url') String? externalUrl, |
| 40 | + String? title, |
| 41 | + @JsonKey(name: 'content_html') String? contentHtml, |
| 42 | + @JsonKey(name: 'content_text') String? contentText, |
| 43 | + String? summary, |
| 44 | + String? image, |
| 45 | + @JsonKey(name: 'banner_image') String? bannerImage, |
| 46 | + @JsonKey(name: 'date_published') String? datePublished, |
| 47 | + @JsonKey(name: 'date_modified') String? dateModified, |
| 48 | + List<Author>? authors, |
| 49 | + List<String>? tags, |
| 50 | + String? language, |
| 51 | + List<Attachment>? attachments, |
| 52 | + }) = _Item; |
| 53 | + |
| 54 | + factory Item.fromJson(Map<String, dynamic> json) => _$ItemFromJson(json); |
| 55 | +} |
| 56 | + |
| 57 | +@freezed |
| 58 | +abstract class JsonFeed with _$JsonFeed { |
| 59 | + const factory JsonFeed({ |
| 60 | + required String version, |
| 61 | + required String title, |
| 62 | + @JsonKey(name: 'home_page_url') String? homePageUrl, |
| 63 | + @JsonKey(name: 'feed_url') String? feedUrl, |
| 64 | + String? description, |
| 65 | + @JsonKey(name: 'user_comment') String? userComment, |
| 66 | + @JsonKey(name: 'next_url') String? nextUrl, |
| 67 | + String? icon, |
| 68 | + String? favicon, |
| 69 | + List<Author>? authors, |
| 70 | + String? language, |
| 71 | + bool? expired, |
| 72 | + List<Hub>? hubs, |
| 73 | + @Default([]) List<Item> items, |
| 74 | + }) = _JsonFeed; |
| 75 | + |
| 76 | + factory JsonFeed.fromJson(Map<String, dynamic> json) => |
| 77 | + _$JsonFeedFromJson(json); |
| 78 | +} |
0 commit comments