Skip to content

Instantly share code, notes, and snippets.

@azamsharp
Created January 13, 2020 16:07
Show Gist options
  • Select an option

  • Save azamsharp/471cf095fdf2aeb71272b6d4162b2702 to your computer and use it in GitHub Desktop.

Select an option

Save azamsharp/471cf095fdf2aeb71272b6d4162b2702 to your computer and use it in GitHub Desktop.
Future<List<NewsArticle>> getTopNews() async {
final url = "https://silicon-rhinoceros.glitch.me/top-news";
final response = await http.get(url);
if(response.statusCode == 200) {
Iterable json = jsonDecode(response.body);
return json.map((newsArticle) => NewsArticle.fromJson(newsArticle)).toList();
} else {
throw Exception("Error fetching news");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment