Line data Source code
1 : import 'package:freezed_annotation/freezed_annotation.dart'; 2 : 3 : part 'linkeable.freezed.dart'; 4 : part 'linkeable.g.dart'; 5 : 6 : ///Base class for items that reference by link 7 : /// 8 : ///`MediaLinkeable`, `DocumentLinkeable` or `WebLinkeable` 9 : @Freezed(unionKey: 'link_type', unionValueCase: FreezedUnionCase.snake) 10 : class Linkeable with _$Linkeable { 11 : ///DocumentReference model 12 : /// 13 : ///Handle a reference to document without content 14 : @FreezedUnionValue('Document') 15 : const factory Linkeable.document({ 16 : @JsonKey(name: 'link_type') required String linkType, 17 : required List<String> tags, 18 : required String id, 19 : required String lang, 20 : required String slug, 21 : required String type, 22 : required bool isBroken, 23 : }) = DocumentLinkeable; 24 : 25 : ///Media model 26 : /// 27 : ///Handle media data from the library 28 : @FreezedUnionValue('Media') 29 : const factory Linkeable.media({ 30 : @JsonKey(name: 'link_type') required String linkType, 31 : String? height, 32 : String? width, 33 : required String kind, 34 : required String name, 35 : required String size, 36 : required String url, 37 : }) = MediaLinkeable; 38 : 39 : ///Web model 40 : /// 41 : ///Handle a simple link reference 42 : @FreezedUnionValue('Web') 43 : const factory Linkeable.web({ 44 : @JsonKey(name: 'link_type') required String linkType, 45 : required String url, 46 : }) = WebLinkeable; 47 : 48 : ///Creates a Linkeable object from json 49 : /// 50 : ///Can create a `MediaLinkeable`, `DocumentLinkeable` or 51 : ///`WebLinkeable` depending on `link_type` from json. 52 1 : factory Linkeable.fromJson(Map<String, dynamic> json) => 53 1 : _$LinkeableFromJson(json); 54 : }