I want to get data from API. I have no idea how to connect it..
I am for a beginner for this.
this is the widget documentation : https://pub.dev/packages/infinite_view_pager
class _NewsTimelineState extends State<NewsTimeline> {
int index = 0;
List pnews = [];
bool isLoading = false;
void initState() {
// TODO: implement initState
super.initState();
this.fetchUser();
}
fetchUser() async {
setState(() {
isLoading = true;
});
var url = "##api";
var response = await http.get(url);
print(response.body);
if(response.statusCode == 200){
print(response.statusCode);
var news = json.decode(response.body);
setState(() {
pnews = news;
isLoading = false;
});
}else{
pnews = [];
isLoading = false;
}
}
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…