Skip to content

Instantly share code, notes, and snippets.

@wilburx9
Created April 2, 2018 12:17
Show Gist options
  • Save wilburx9/988da34565111e697b4e95667f6f19d1 to your computer and use it in GitHub Desktop.
Save wilburx9/988da34565111e697b4e95667f6f19d1 to your computer and use it in GitHub Desktop.
class Post {
String title;
String summary;
String thumbUrl;
int timeStamp;
String url;
Post(this.title, this.summary, this.thumbUrl, this.timeStamp, this.url);
static Post getPostFrmJSONPost(dynamic jsonObject) {
String title = jsonObject['title'];
String url = jsonObject['url'];
String summary = jsonObject['abstract'];
List multiMediaList = jsonObject['multimedia'];
// We want an average-quality image or nothing
String thumbUrl = multiMediaList.length > 4? multiMediaList[3]['url'] : "";
int timeStamp = DateTime.parse(jsonObject['created_date']).millisecondsSinceEpoch;
return new Post(title, summary, thumbUrl, timeStamp, url);
}
@override
String toString() {
return "title = $title; summary = $summary; thumgnail = $thumbUrl; "
"timeStamp = $timeStamp; url = $url";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment