import 'package:teso/Classes/API%20Clasess/CampAd.dart'; import 'package:teso/Classes/API%20Clasess/CommentsPost.dart'; import 'package:teso/Classes/API%20Clasess/Post.dart'; import 'package:teso/Classes/API%20Clasess/PostFav.dart'; import 'package:teso/Classes/TesoUser.dart'; class PostedAd { Post? post; List? likes; List? comments; bool? campaignAd; CampAd? campAdvert; TesoUser? publisher; PostedAd({ this.post, this.likes, this.comments, List? friends, this.campaignAd, this.campAdvert, this.publisher, }); factory PostedAd.fromJSON(Map json) { var favorites = json["likes"] as List; List favs = favorites.map((e) => PostFav.fromJSON(e)).toList(); var comments = json["comments"] as List; List cmnt = comments.map((e) => CommentsPost.fromJSON(e)).toList(); return PostedAd( post: Post.fromJSON(json["post"]), likes: favs, comments: cmnt, campaignAd: json["campaignAd"], campAdvert: json["campaignAdvert"] != null ? CampAd.fromJSON(json["campaignAdvert"]) : null, publisher: json["publisher"] != null ? TesoUser.fromJSON(json["publisher"]) : null, ); } Map toJson() { final Map data = Map(); data['post'] = this.post; data['likes'] = this.likes; data['comments'] = this.comments; data['campaignAd'] = this.campaignAd; data['campaignAdvert'] = this.campaignAd; data['publisher'] = this.publisher; return data; } @override String toString() { return '{"post": "$post", "likes": "$likes", "comments": "$comments","campaignAd" :"$campaignAd","campaignAdvert":"$campAdvert", "publisher":"$publisher"}'; } }