Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何从Flatter中的Firebase实时数据库中按类别获取产品?_Firebase_Flutter_Rest_Firebase Realtime Database - Fatal编程技术网

如何从Flatter中的Firebase实时数据库中按类别获取产品?

如何从Flatter中的Firebase实时数据库中按类别获取产品?,firebase,flutter,rest,firebase-realtime-database,Firebase,Flutter,Rest,Firebase Realtime Database,我正在尝试从Flatter中的Firebase实时数据库中获取并显示分类产品。每个产品的producst.json中都有特定的categoryId。为此,我写了一个这样的查询。 但我买不到产品。我该怎么写 多谢各位 static Future getProductsByCategoryId(int categoryId){ return http.get("https://--projectlink--.firebaseio.com/myapp/products.jsoncate

我正在尝试从Flatter中的Firebase实时数据库中获取并显示分类产品。每个产品的producst.json中都有特定的categoryId。为此,我写了一个这样的查询。 但我买不到产品。我该怎么写

多谢各位

static Future getProductsByCategoryId(int categoryId){
   return http.get("https://--projectlink--.firebaseio.com/myapp/products.jsoncategoryId=$categoryId");
}

你构造的URL不对。对于Firebase REST API,
.json
后缀必须位于URL的末尾

因此:


“我买不到产品”为什么不?您共享的代码有什么问题?http.get(“https://--projectlink--.firebaseio.com/myapp/products.json"); 当我调用此查询时,产品显示出来,但当我使用categoryId调用它时,我无法得到任何产品。它给出所有产品,而不是带有categoryId/Flatter(4509)的特定产品:[错误:Flatter/lib/ui/ui\u dart\u state.cc(177)]未处理的异常:FormatException:意外字符(在第2行,字符1)E/Flatter(4509)当前位置抱歉,但不起作用是的,我现在意识到您正在尝试执行一个查询,它看起来与您所做的完全不同。我更新了我的答案,但大多数情况下,这只是字符串操作,直到您匹配文档:非常感谢您的答案,但它不再起作用。我试过json服务器,里面没有问题。但是,firebase无法处理相同的查询。下面是针对测试数据库中数据的工作URL:
https://stackoverflow.firebaseio.com/67244097.json?orderBy=“categoryId”&equalTo=“a”
检查您的代码是否生成相同的URL。感谢您的回答。我解决了。它给出了未将indexOn属性添加到颤振数据库规则的错误原因。
http.get("https://--projectlink--.firebaseio.com/myapp/products.json?orderBy=\"categoryId\"&equalTo=\"$categoryId\"");