Skip to content

Instantly share code, notes, and snippets.

@ashishrawat2911
Last active May 6, 2019 17:20
Show Gist options
  • Save ashishrawat2911/8a8cd94761b491e6876c8b1308f0cb78 to your computer and use it in GitHub Desktop.
Save ashishrawat2911/8a8cd94761b491e6876c8b1308f0cb78 to your computer and use it in GitHub Desktop.
Future<List<Article>> getData(String newsType) async {
List<Article> list;
String link =
"https://newsapi.org/v2/top-headlines?country=in&apiKey=API_KEY";
var res = await http
.get(Uri.encodeFull(link), headers: {"Accept": "application/json"});
print(res.body);
if (res.statusCode == 200) {
var data = json.decode(res.body);
var rest = data["articles"] as List;
print(rest);
list = rest.map<Article>((json) => Article.fromJson(json)).toList();
}
print("List Size: ${list.length}");
return list;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment