[英]Flutter FirebaseAnimatedList query is not working properly
I tried to fetch some data from the firebase realtime database using a FirebaseAnimatedList()
using a search query which should be query : ref.child("users").child(userPath).orderByChild("id").equalTo(userID)
but instead of that query works without second child like this query : ref.child("users").orderByChild("id").equalTo(userID)
我尝试使用FirebaseAnimatedList()
使用应该query : ref.child("users").child(userPath).orderByChild("id").equalTo(userID)
的搜索查询从 firebase 实时数据库中获取一些数据query : ref.child("users").child(userPath).orderByChild("id").equalTo(userID)
但该查询在没有第二个孩子的情况下工作,而不是这样的query : ref.child("users").orderByChild("id").equalTo(userID)
And it seems like when data is passed .equalTo(userID)
if passed userID is not found in the database it loads a blank container I'm looking for a way to avoid loading a blank container and return a custom view if there's no value that matches .equalTo(userID)
似乎当传递数据时.equalTo(userID)
如果在数据库中找不到传递的 userID 它会加载一个空白容器我正在寻找一种方法来避免加载空白容器并返回自定义视图如果没有值匹配.equalTo(userID)
realtime database example :实时数据库示例:
{
"users" : {
"user1" : {
"lname" : "dee",
"id" : "12"
},
"user2" : {
"lname" : "nee",
"id" : "13"
},
"user3" : {
"lname" : "lee",
"id" : "14"
},
"user4" : {
"lname" : "bree",
"id" : "15"
}
}
Code :代码 :
FirebaseAnimatedList(
query: ref.child("users").orderByChild("id").equalTo(this.userid),
itemBuilder: (BuildContext context, DataSnapshot snapshot,
Animation<double> animation, int index) {
return SizeTransition(
sizeFactor: animation,
axis: Axis.horizontal,
axisAlignment: -0.8,
child: Column(
textDirection: TextDirection.ltr,
verticalDirection: VerticalDirection.down,
children: <Widget>[
SizedBox(
height: 100.0,
),
Text(
"User ID : " + snapshot.value["id"],
),
SizedBox(
height: 50.0,
),
],
),
);
}));
The query is actually correct, to be able to access the id
using orderByChild("id")
, you dont need to use another child()
method.查询实际上是正确的,为了能够使用orderByChild("id")
访问id
,您不需要使用另一个child()
方法。
I'm looking for a way to avoid loading a blank container and return a custom view我正在寻找一种避免加载空白容器并返回自定义视图的方法
FirebaseAnimatedList(
query: ref.child("users").orderByChild("id").equalTo(this.userid),
itemBuilder: (BuildContext context, DataSnapshot snapshot,
Animation<double> animation, int index) {
if(snapshot.value != null){
return SizeTransition(
sizeFactor: animation,
axis: Axis.horizontal,
axisAlignment: -0.8,
child: Column(
textDirection: TextDirection.ltr,
verticalDirection: VerticalDirection.down,
children: <Widget>[
SizedBox(
height: 100.0,
),
Text(
"User ID : " + snapshot.value["id"],
),
SizedBox(
height: 50.0,
),
],
),
);
}
else{
return Text("no Data");
}
return CircularProgressIndicator();
}));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.