Last active
May 6, 2019 17:20
-
-
Save ashishrawat2911/8a8cd94761b491e6876c8b1308f0cb78 to your computer and use it in GitHub Desktop.
This file contains 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<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