didvan-app/lib/models/news_details_data.dart

61 lines
1.6 KiB
Dart

import 'package:didvan/models/content.dart';
import 'package:didvan/models/item_overview.dart';
import 'package:didvan/models/tag.dart';
class NewsDetailsData {
final int id;
final String title;
final String reference;
final String image;
final String createdAt;
final bool marked;
int comments;
final int order;
final List<Tag> tags;
final List<Content> contents;
final List<OverviewData> relatedContents = [];
NewsDetailsData({
required this.id,
required this.title,
required this.reference,
required this.image,
required this.createdAt,
required this.marked,
required this.comments,
required this.tags,
required this.contents,
required this.order,
});
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'],
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,
'comments': comments,
'tags': tags.map((e) => e.toJson()).toList(),
'contents': contents.map((e) => e.toJson()).toList(),
};
}