When i refresh the data isnt fetching new data please help me
This is my method to fetch data from news org api
Future<List<Article>> getApi() async {
Response response = await get(Uri.parse(
"https://newsapi.org/v2/top-headlines?country=us&category=business&apiKey=apikey"));
if (response.statusCode == 200) {
Map<String, dynamic> json = jsonDecode(response.body);
List<dynamic> body = json['articles'];
List<Article> article = body.map((e) => Article.fromJson(e)).toList();
return article;
} else {
throw ("cant get the articles");
}
}
this is my builder to show data
body: FutureBuilder<List<Article>>(
future: futureWords,
builder: (context, AsyncSnapshot<List<Article>> snap) {
if (snap.hasData) {
List<Article> articles = snap.data!;
return RefreshIndicator(
onRefresh: () {
setState(() {});
return _pullRefresh();
},
child: ListView.builder(
itemCount: 20,
itemBuilder: (context, index) {
return customListTile(articles[index]);
}),
);
} else {
return Center(child: CircularProgressIndicator());
}
}),
this is my pullrefresh method
Future<List<Article>> _pullRefresh() async {
List<Article> freshWords = await news.getApi();
setState(() {
futureWords = Future.value(freshWords);
});
return futureWords!;
}