78 lines
2.0 KiB
Dart
78 lines
2.0 KiB
Dart
import 'package:didvan/models/category.dart';
|
|
import 'package:html/parser.dart';
|
|
|
|
class OverviewData {
|
|
final int id;
|
|
final String title;
|
|
final String image;
|
|
final String description;
|
|
final int? timeToRead;
|
|
final int? duration;
|
|
final String? reference;
|
|
final String? media;
|
|
final bool forManagers;
|
|
final String createdAt;
|
|
final String type;
|
|
int comments;
|
|
bool marked;
|
|
final List<CategoryData>? categories;
|
|
|
|
OverviewData({
|
|
required this.id,
|
|
required this.title,
|
|
required this.image,
|
|
required this.description,
|
|
required this.createdAt,
|
|
required this.type,
|
|
required this.marked,
|
|
required this.comments,
|
|
required this.forManagers,
|
|
this.media,
|
|
this.duration,
|
|
this.timeToRead,
|
|
this.reference,
|
|
this.categories,
|
|
});
|
|
|
|
factory OverviewData.fromJson(Map<String, dynamic> json) {
|
|
final document = parse(json['description']);
|
|
final String parsedString =
|
|
parse(document.body!.text).documentElement!.text;
|
|
return OverviewData(
|
|
id: json['id'],
|
|
title: json['title'],
|
|
image: json['image'],
|
|
description: parsedString,
|
|
timeToRead: json['timeToRead'],
|
|
reference: json['reference'],
|
|
forManagers: json['forManagers'] ?? false,
|
|
comments: json['comments'] ?? 0,
|
|
createdAt: json['createdAt'],
|
|
duration: json['duration'],
|
|
type: json['type'] ?? '',
|
|
marked: json['marked'] ?? true,
|
|
media: json['media'],
|
|
categories: json['categories'] != null
|
|
? List<CategoryData>.from(
|
|
json['categories'].map(
|
|
(e) => CategoryData.fromJson(e),
|
|
),
|
|
)
|
|
: null,
|
|
);
|
|
}
|
|
|
|
Map<String, dynamic> toJson() => {
|
|
'id': id,
|
|
'title': title,
|
|
'image': image,
|
|
'description': description,
|
|
'timeToRead': timeToRead,
|
|
'reference': reference,
|
|
'forManagers': forManagers,
|
|
'createdAt': createdAt,
|
|
'type': type,
|
|
'categories': categories?.map((e) => e.toJson()).toList(),
|
|
};
|
|
}
|