Dart 颤振:如何使用JSON加载所有分页数据

Dart 颤振:如何使用JSON加载所有分页数据,dart,flutter,Dart,Flutter,我有一个wordpress页面,在那里我发布文章。 当我在Wordpress中超过10个出版物时,就会发现问题,应用程序只接收最近10个出版物 我想实现显示所有帖子的功能。但我不知道如何开始 目前我有15份出版物,如图所示,只显示了最后10份,我希望解决这个问题,谢谢 这是我的JSON代码 [ { "id": 65, "date": "2014-08-24T18:56:26", "date_gmt": "2014-08-24T18:56:26", "g

我有一个wordpress页面,在那里我发布文章。 当我在Wordpress中超过10个出版物时,就会发现问题,应用程序只接收最近10个出版物

我想实现显示所有帖子的功能。但我不知道如何开始

目前我有15份出版物,如图所示,只显示了最后10份,我希望解决这个问题,谢谢

这是我的JSON代码

    [
  {
    "id": 65,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 1 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 1</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 1...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 650,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 2 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 2</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 2...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 3 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 3</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 3...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 236,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 4 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 4</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 4...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 330,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 5 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 5</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 5...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 6 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 6</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 6...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 7 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 7</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 7...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 8 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 8</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 8...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 9 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 9</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 9...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 10 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 10</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 10...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
  {
    "id": 230,
    "date": "2014-08-24T18:56:26",
    "date_gmt": "2014-08-24T18:56:26",
    "guid": {
      "rendered": "http:\/\/********\/********\/?p=1"
    },
    "modified": "2018-06-05T13:24:58",
    "modified_gmt": "2018-06-05T13:24:58",
    "slug": "this-url-wordpress",
    "status": "publish",
    "type": "post",
    "title": {
      "rendered": "\u2018 This a test title 11 \u2019"
     },
     "content": {
       "rendered": "<p>This is a content 11</p>",
       "protected": false
     },
     "excerpt": {
       "rendered": "<p>this a excerpt 11...<\/p>\n",
       "protected": false
     },
     "author": 1,
     "featured_media": 468,
     "comment_status": "open",
     "ping_status": "open",
     "sticky": false,
     "template": "",
     "format": "standard",
     "meta": [ 
     ],
     "categories": [
      14
     ],
     "tags": [
      17,
      18
     ],
  },
]
[
{
“id”:65,
“日期”:“2014-08-24T18:56:26”,
“日期”:“2014-08-24T18:56:26”,
“guid”:{
“呈现”:“http:\/\/*********\/************\/?p=1”
},
“修改”:“2018-06-05T13:24:58”,
“修改后的gmt”:“2018-06-05T13:24:58”,
“slug”:“此url wordpress”,
“状态”:“发布”,
“类型”:“职位”,
“标题”:{
“呈现”:“\u2018这是测试标题1\u2019”
},
“内容”:{
“呈现”:“这是一个内容1

”, “受保护”:错误 }, “摘录”:{ “呈现”:“这是摘录1…\n”, “受保护”:错误 }, "作者":1,, “特色媒体”:468, “评论状态”:“打开”, “ping_状态”:“打开”, “粘性”:假, “模板”:“, “格式”:“标准”, “元”:[ ], “类别”:[ 14 ], “标签”:[ 17, 18 ], }, { “id”:650, “日期”:“2014-08-24T18:56:26”, “日期”:“2014-08-24T18:56:26”, “guid”:{ “呈现”:“http:\/\/*********\/************\/?p=1” }, “修改”:“2018-06-05T13:24:58”, “修改后的gmt”:“2018-06-05T13:24:58”, “slug”:“此url wordpress”, “状态”:“发布”, “类型”:“职位”, “标题”:{ “呈现”:“\u2018这是测试标题2\u2019” }, “内容”:{ “呈现”:“这是内容2

”, “受保护”:错误 }, “摘录”:{ “呈现”:“这是摘录2…\n”, “受保护”:错误 }, "作者":1,, “特色媒体”:468, “评论状态”:“打开”, “ping_状态”:“打开”, “粘性”:假, “模板”:“, “格式”:“标准”, “元”:[ ], “类别”:[ 14 ], “标签”:[ 17, 18 ], }, { “id”:230, “日期”:“2014-08-24T18:56:26”, “日期”:“2014-08-24T18:56:26”, “guid”:{ “呈现”:“http:\/\/*********\/************\/?p=1” }, “修改”:“2018-06-05T13:24:58”, “修改后的gmt”:“2018-06-05T13:24:58”, “slug”:“此url wordpress”, “状态”:“发布”, “类型”:“职位”, “标题”:{ “呈现”:“\u2018这是测试标题3\u2019” }, “内容”:{ “呈现”:“这是一个内容3

”, “受保护”:错误 }, “摘录”:{ “呈现”:“这是摘录3…\n”, “受保护”:错误 }, "作者":1,, “特色媒体”:468, “评论状态”:“打开”, “ping_状态”:“打开”, “粘性”:假, “模板”:“, “格式”:“标准”, “元”:[ ], “类别”:[ 14 ], “标签”:[ 17, 18 ], }, { “id”:236, “日期”:“2014-08-24T18:56:26”, “日期”:“2014-08-24T18:56:26”, “guid”:{ “呈现”:“http:\/\/*********\/************\/?p=1” }, “修改”:“2018-06-05T13:24:58”, “修改后的gmt”:“2018-06-05T13:24:58”, “slug”:“此url wordpress”, “状态”:“发布”, “类型”:“职位”, “标题”:{ “呈现”:“\u2018这是测试标题4\u2019” }, “内容”:{ “呈现”:“这是一个内容4

”, “受保护”:错误 }, “摘录”:{ “呈现”:“这是摘录4…\n”, “受保护”:错误 }, "作者":1,, “特色媒体”:468, “评论状态”:“打开”, “ping_状态”:“打开”, “粘性”:假, “模板”:“, “格式”:“标准”, “元”:[ ], “类别”:[ 14 ], “标签”:[ 17, 18 ], }, { “id”:330, “日期”:“2014-08-24T18:56:26”, “日期”:“2014-08-24T18:56:26”, “guid”:{ “呈现”:“http:\/\/*********\/************\/?p=1” }, “修改”:“2018-06-05T13:24:58”, “修改后的gmt”:“2018-06-05T13:24:58”, “slug”:“此url wordpress”, “状态”:“发布”, “类型”:“职位”, “标题”:{ “呈现”:“\u2018这是测试标题5\u2019” }, “内容”:{ “呈现”:“这是一个内容5

”, “受保护”:错误 }, “摘录”:{ “呈现”:“这是摘录5…\n”, “受保护”:错误 }, "作者":1,, “特色媒体”:468, “评论状态”:“打开”, “ping_状态”:“打开”, “粘性”:假, “模板”:“, “格式”:“标准”, “元”:[ ], “类别”:[ 14 ], “标签”:[ 17, 18 ], }, { “id”:230, “日期”:“2014-08-24T18:56:26”, “日期”:“2014-08-24T18:56:26”, “guid”:{ “呈现”:“http:\/\/*********\/************\/?p=1” }, “修改”:“2018-06-05T13:24:58”, “修改后的gmt”:“2018-06-05T13:24:58”, “slug”:“此url wordpress”, “状态”:“发布”, “类型”:“职位”, “标题”:{ “呈现”:“\u2018这是测试标题6\u2019” }, “内容”:{ “呈现”:“这是一个内容6

”, “受保护”:错误 }, “摘录”:{ “呈现”:“这是摘录6…\n”, “受保护”:错误 }, "作者":1,, “特色媒体”:468, “评论状态”:“打开”, “ping_状态”:“打开”, “粘性”:假, “模板”:“, “格式”:“标准”, “元”:[ ], “类别”:[ 14 ], “标签”:[ 17, 18 ], }, { “id”:230, “日期”:“2014-08-24T18:56:2
Future<List<Post>> fetchPosts() async {
  http.Response response =
  await http.get("http://*********:88/WordPress/wp-json/wp/v2/posts/");
  List responseJson = json.decode(response.body);
  return responseJson.map((m) => new Post.fromJson(m)).toList();
}

class Post {
    final String title;
    final String body;
    final String content;
    final String urlimagen;
    final String linkWeb;

  Post({this.title, this.body, this.content, this.urlimagen, this.linkWeb});

  factory Post.fromJson(Map<String, dynamic> json) {
      return new Post(
        title: json['title']['rendered'].toString(),
        body: json['excerpt']['rendered'].toString(),
        content: json['content']['rendered'].toString(),
        linkWeb: json['link'].toString(),
      );
    }
  }

  class NewsState extends State<NewsPage> {
    int _count = 0;

    @override
    Widget build(BuildContext context) {
      return Scaffold(
        appBar: new AppBar(
          title: new Text("Noticias"),
          centerTitle: true,
          backgroundColor: Colors.deepOrange[700],
        ),
        body: new Container(
          child: new RefreshIndicator(
              child: new ListView(
                children: <Widget>[
                 new FutureBuilder<List<Post>>(
                      future: fetchPosts(),
                      builder: (context, snapshotImg) {
                        if (snapshotImg.hasData){
                          List<Post> posts = snapshotImg.data;
                          return new Column(
                          children: posts.map((post) => new Column(
                          children: _getItems(post.title, post.body, post.content, post.linkWeb),
                          )).toList()
                        );
                      }
                      else if(snapshotImg.hasError)
                      {
                        return new Text("${snapshotImg.error}");
                      }
                        return new Center(
                          child: new Column(
                             children: <Widget>[
                              new Padding(padding: new dgeInsets.all(50.0)),
                              new CircularProgressIndicator(),
                            ],
                          ),
                        );
                      },
                    ),
                  ],
                ),
              onRefresh: _handleRefresh,
          ),
        )
      );
    }

    List<Widget> _getItems(String title, String description, String content, String url) {
      var items = <Widget>[];
      var item = new Column(
          children: <Widget>[
            new ListTile(
              leading: new Icon(Icons.language, color: Colors.deepOrange[700], size: 30.0,),
              title: new Text(title),
              subtitle: new Text(description),
              onTap: ()
              {
                Navigator.push(
                    context,
                    new MaterialPageRoute(builder: (context) => new WebView(url: url, title: title)));
              },
            ),
                  new Divider(
                    color: Colors.deepOrange[700],
              height: 2.0,
            ),
          ],
        );
        items.add(item);
      return items;
    }

    Future<Null> _handleRefresh() async {
      await new Future.delayed(new Duration(seconds: 3));

      setState(() {
        _count += 5;
      });

      return null;
    }
}