api数据在flutter中的分页



我从API中获取数据,如demo:-

{draw: 0, records Total: 210, records Filtered: 210, data: [,…], input: []}
data: [,…]
draw: 0
input: []
records Filtered: 210
records Total: 210

我想在API数据(网格视图或列表视图)上应用分页

我该怎么做呢?

您的json结构需要看起来像这样,以便轻松应用分页。使用current pagenext pagelast page来确定下一页、当前页和剩余页。

您可以直接使用next链接获取下一页的数据。

{
"meta": {
"page": {
"current-page": 2,
"per-page": 15,
"from": 16,
"to": 30,
"total": 50,
"last-page": 4
}
},
"links": {
"first": "http://localhost/api/v1/posts?page[number]=1&page[size]=15",
"prev": "http://localhost/api/v1/posts?page[number]=1&page[size]=15",
"next": "http://localhost/api/v1/posts?page[number]=3&page[size]=15",
"last": "http://localhost/api/v1/posts?page[number]=4&page[size]=15"
},
"data": [...]
}