Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
425 views
in Technique[技术] by (71.8m points)

dart - How to connect API in infinite_view_pager widget - flutter

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;
    }
  }
}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
等待大神答复

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...