我有一个带有主体的 Scaffold
:
body: new Column(
children: <Widget>[
new Flexible(
child: new FirebaseAnimatedList(
query: FirebaseDatabase.instance
.reference()
.child('products')
.orderByChild('order'),
padding: new EdgeInsets.all(8.0),
reverse: false,
itemBuilder: (_, DataSnapshot snapshot,
Animation<double> animation, int x) {
return new ProductItem(
snapshot: snapshot, animation: animation);
},
),
),
],
),
但我需要添加一个简单的查询:'Active' = true
有可能吗?如何?任何示例/教程?
谢谢。
最佳答案
如果我没有正确回答您的问题,您正在尝试查询一些数据 where ("Active"= true),请参阅以下示例。
我从我的数据库中添加了一个屏幕截图,以便对我的数据结构方式有更多的背景信息,并希望它能让您了解最终实现类似的东西。
在前面的示例中,我正在执行以下查询以仅获取设置为“em1@gmail.com”的电子邮件的联系人,而忽略其他人。
@override
Widget build(BuildContext context) {
return new Scaffold(
appBar: new AppBar(title: new Text("Firebase Example"),),
body: new Column(
children: <Widget>[
new Flexible(
child: new FirebaseAnimatedList(
query: FirebaseDatabase.instance
.reference().child("contacts")
.orderByChild("email")
.startAt("em1@gmail.com").endAt("em1@gmail.com"),
padding: new EdgeInsets.all(8.0),
reverse: false,
itemBuilder: (_, DataSnapshot snapshot,
Animation<double> animation, int x) {
return new ListTile(
subtitle: new Text(snapshot.value.toString()),
);
}
),
),
],
),
);
}
希望对您有所帮助。
P.S:如 Chenna Reddy指出,您可以替换startAt("em1@gmail.com").endAt("em1@gmail.com")
由 equalTo("em1@gmail.com")
startAt
和 endAt
当您需要将查询限制在某个范围内时很有用。
For more information.
关于firebase - 如何使用 buildArguments 或其他任何东西在 Flutter/FirebaseAnimatedList 中查询? (请举例),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46912713/
相关文章:
firebase - flutter/Dart 错误 : The argument type 'Fu
dart - Flutter 中的 Scaffold 和 MaterialApp 有什么区别?
flutter - Flutter中的Material和MaterialApp有什么区别?
unit-testing - Flutter/Dart 在单元测试中等待几秒钟
dart - 如何在 Flutter 中获取 Text 小部件的大小
dart - flutter : Get Local position of Gesture Det