I have following code
class FavoriteItem {
String headline;
String content;
String link;
String publisheddate;
FavoriteItem({this.headline, this.content, this.link, this.publisheddate});
toJSONEncodable() {
Map<String, dynamic> m = new Map();
m['headline'] = headline;
m['content'] = content;
m['link'] = link;
m['publisheddate'] = publisheddate;
return m;
}
}
class FavoriteList {
List<FavoriteItem> items;
FavoriteList() {
items = new List();
}
toJSONEncodable() {
return items.map((item) {
return item.toJSONEncodable();
}).toList();
}
}
And i have initiated the class like this
final FavoriteList favlist = new FavoriteList(); and i populate favlist with following code from json
if (items != null) {
(items as List).forEach((item) {
final favoriteitem = new FavoriteItem(headline: item['headline'], content: item['content'], link: item['link'], publisheddate: item['publisheddate']);
favlist.items.add(favoriteitem);
});
}
Problem
What I want to do is to check if object favoriteitem already exist in favlist before adding.
I tried using -
favlist.items.contains
favlist.items.indexof but didn't work
I am new to flutter/dart, can anybody please help me on this