Created
January 13, 2020 16:07
-
-
Save azamsharp/471cf095fdf2aeb71272b6d4162b2702 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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