67 lines
1.8 KiB
Dart
67 lines
1.8 KiB
Dart
import 'package:didvan/models/content.dart';
|
|
import 'package:didvan/models/overview_data.dart';
|
|
import 'package:didvan/models/tag.dart';
|
|
|
|
class NewsDetailsData {
|
|
final int id;
|
|
final String title;
|
|
final String reference;
|
|
final String image;
|
|
final String createdAt;
|
|
bool marked;
|
|
bool liked;
|
|
int comments;
|
|
final int order;
|
|
final List<Tag> tags;
|
|
final List<Content> contents;
|
|
final List<OverviewData> relatedContents = [];
|
|
bool relatedContentsIsEmpty;
|
|
|
|
NewsDetailsData({
|
|
required this.id,
|
|
required this.title,
|
|
required this.reference,
|
|
required this.image,
|
|
required this.createdAt,
|
|
required this.marked,
|
|
required this.liked,
|
|
required this.comments,
|
|
required this.tags,
|
|
required this.contents,
|
|
required this.order,
|
|
this.relatedContentsIsEmpty = false,
|
|
});
|
|
|
|
factory NewsDetailsData.fromJson(Map<String, dynamic> json) {
|
|
return NewsDetailsData(
|
|
id: json['id'],
|
|
title: json['title'],
|
|
reference: json['reference'],
|
|
image: json['image'],
|
|
createdAt: json['createdAt'],
|
|
marked: json['marked'],
|
|
liked: json['liked'] ?? false,
|
|
comments: json['comments'],
|
|
order: json['order'],
|
|
tags: List<Tag>.from(json['tags'].map((tag) => Tag.fromJson(tag))),
|
|
contents: List<Content>.from(json['contents'].map(
|
|
(content) => Content.fromJson(content),
|
|
)),
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'title': title,
|
|
'order': order,
|
|
'reference': reference,
|
|
'image': image,
|
|
'createdAt': createdAt,
|
|
'marked': marked,
|
|
'liked': liked,
|
|
'comments': comments,
|
|
'tags': tags.map((e) => e.toJson()).toList(),
|
|
'contents': contents.map((e) => e.toJson()).toList(),
|
|
};
|
|
}
|