【发布时间】:2020-12-15 07:57:18
【问题描述】:
如何在 Flutter 中使用 HTTP 请求在实时数据库中实现分页?我尝试了以下方法,但它返回了错误。
Future<List<News>> fetchNews() async {
final response = await http.get("https://<project-id>.firebaseio.com/posts.json?orderBy='t'&limitToFirst=10");
Map map = json.decode(response.body);
map.forEach((NewsId, NewsData) {
_list.add(News.fromJson(NewsData));
});
return _list;
}
返回的错误是:
I/flutter (18683): {
I/flutter (18683): "error" : "orderBy must be a valid JSON encoded path"
I/flutter (18683): }
我试图用这个替换网址:https://project-id.firebaseio.com/posts.json?orderBy=(backslash)"t(backslash)"&limitToFirst=10 但我收到的错误是这样的:
I/flutter (18683): {
I/flutter (18683): "error" : "Index not defined, add \".indexOn\": \"t\", for path \"/posts\", to the rules"
I/flutter (18683): }
任何有关如何实现分页的帮助都会有所帮助。我也不介意恢复使用包而不是 http 请求。如果这两种方法之间有任何显着差异,我将不胜感激。
我的数据库结构如下:
<project-id>
|__posts
|____(unique key1)
|_____field1
|_____field2
|_____field3
|____(unique key2)
|____(unique key3)
提前致谢。
【问题讨论】:
标签: flutter dart firebase-realtime-database httprequest