如何使用buildArguments或其他方法查询Flutter / FirebaseAnimatedList? (请举个例子) [英] How to query in a Flutter/FirebaseAnimatedList using buildArguments or anything else? (example please)

查看:131
本文介绍了如何使用buildArguments或其他方法查询Flutter / FirebaseAnimatedList? (请举个例子)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个这样的 Scaffold ,带有主体:

I have a this Scaffold with body:

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

but I need to add a simple query: 'Active' = true

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

Is it possible? How? Any example/tutorial?

谢谢。

推荐答案

如果我是正确回答您的问题,您正在尝试查询一些数据( Active = true),然后查看以下示例。

If I am getting your question correctly, you are trying to query some data where ("Active" = true), then see the following example.

我已从数据库中添加了屏幕截图以获得有关我的数据结构方式的更多信息,并希望它能使您透视实现自己的目标。

I have added a screenshot from my db to have more context on the way my data is structured and hopefully it will put you into perspective to implement something similar on your end.

在上一个示例中,我正在执行以下查询,以仅获取设置为 em1@gmail.com的电子邮件的联系人,而忽略其他联系人。 / p>

In the previous example, I am doing the following query to only obtain contact of email set to "em1@gmail.com" while neglecting the others.

 @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()),
                  );
                }
            ),
          ),
        ],
      ),
    );
  }

希望有帮助。

PS:正如 Chenna Reddy 指出的那样,您可以替换 startAt( em1 @ gmail.com)。endAt( em1@gmail.com) equalTo( em1@gmail.com)

P.S: As Chenna Reddy pointed out, you can replace startAt("em1@gmail.com").endAt("em1@gmail.com") by equalTo("em1@gmail.com")

startAt endAt 很有用查询到一定范围。

startAt and endAt are useful when you need to limit your query to a certain range.

了解更多信息。

这篇关于如何使用buildArguments或其他方法查询Flutter / FirebaseAnimatedList? (请举个例子)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆