如何使用buildArguments或其他任何东西在Flutter / FirebaseAnimatedList中查询? (请举例)

前端之家收集整理的这篇文章主要介绍了如何使用buildArguments或其他任何东西在Flutter / FirebaseAnimatedList中查询? (请举例)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个带身体的脚手架:

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

可能吗?怎么样?任何示例/教程?

谢谢.

解决方法

如果我正确地得到您的问题,您正在尝试查询某些数据(“Active”= true),然后参见以下示例.

我已经添加了一个来自我的数据库的屏幕截图,以便在我的数据结构方式上有更多的上下文,并希望它能让您直观地实现类似的结果.

enter image description here

在前面的示例中,我正在执行以下查询以仅获取设置为“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"),int x) {
                  return new ListTile(
                    subtitle: new Text(snapshot.value.toString()),);
                }
            ),);
  }

希望它有所帮助.

P.S:正如Chenna Reddy所指出的,你可以用equalTo(“em1@gmail.com”)替换startAt(“em1@gmail.com”).endAt(“em1@gmail.com”)

当您需要将查询限制在特定范围时,startAt和endAt非常有用.

For more information.

猜你在找的Flutter相关文章