import 'package:didvan/models/category.dart'; // ignore: depend_on_referenced_packages 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? link; final String? iframe; final bool forManagers; final String createdAt; final String type; int typeInteger; int comments; bool marked; final List? 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.link, this.iframe, this.duration, this.timeToRead, this.reference, this.categories, this.typeInteger = 0, }) { switch (type) { case 'radar': typeInteger = 1; break; case 'news': typeInteger = 2; break; case 'video': typeInteger = 3; break; case 'podcast': typeInteger = 4; break; case 'saha': typeInteger = 6; break; default: typeInteger = 5; } } factory OverviewData.fromJson(Map json) { String? description; if (json['description'] != null) { final document = parse(json['description']); description = parse(document.body!.text).documentElement!.text; } return OverviewData( id: json['id'], title: json['title'], image: json['image'] ?? 'https://wallpapercave.com/fwp/wp12977378.jpg', description: description ?? '', 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, link: json['link'], iframe: json['iframe'], categories: json['categories'] != null ? List.from( json['categories'].map( (e) => CategoryData.fromJson(e), ), ) : null, ); } Map 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(), }; }