Flutter 带if语句的Flatter Firestore FutureBuilder过滤器

Flutter 带if语句的Flatter Firestore FutureBuilder过滤器,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,我正在尝试筛选FutureBuilder的列表,如下所示: return new FutureBuilder( future: Firestore.instance .collection('user') .getDocuments(), builder: (BuildContext context, AsyncSnaps

我正在尝试筛选FutureBuilder的列表,如下所示:

return new FutureBuilder(
                    future: Firestore.instance
                        .collection('user')
                        .getDocuments(),
                    builder: (BuildContext context, AsyncSnapshot snapshot2) {
                      if (snapshot2.hasData) {
                        if (snapshot2.data != null) {
                          return new Column(
                            children: <Widget>[
                              new Expanded(
                                child: new ListView(
                                  children: snapshot2.data.documents
                                      .map<Widget>((DocumentSnapshot document) {
                                        if(document['first_name'] == 'James') {
                                          return new FindFollowerWidget(
                                            name: document['first_name'] + " " + document['last_name'],
                                            username: document['username'],
                                          );
                                        }
                                  }).toList(),
                                ),
                              ),
                            ],
                          );
                        }
                      }else {
                        return new CircularProgressIndicator();
                      }
                    });
返回新的FutureBuilder(
未来:Firestore.instance
.collection('用户')
.getDocuments(),
生成器:(构建上下文上下文,异步快照快照2){
if(快照2.hasData){
if(快照2.data!=null){
返回新列(
儿童:[
新扩展(
子:新列表视图(
子项:快照2.data.documents
.map((文档快照文档){
如果(文档['first_name']=='James'){
返回新的FindFollowerWidget(
名称:文档['first_name']+''+文档['last_name'],
用户名:文档['username'],
);
}
}).toList(),
),
),
],
);
}
}否则{
返回新的循环ProgressIndicator();
}
});
当我删除if语句时,这个FutureBuilder可以工作;但是,当我包含以下if语句时,它将抛出一个错误:

new ListView(
    children: snapshot2.data.documents.map<Widget>((DocumentSnapshot document) {
        if(document['first_name'] == 'James') {
            return new FindFollowerWidget(
                name: document['first_name'] + " " + document['last_name'],
                username: document['username'],
                );
        }
    ).toList(),
 ),
新建列表视图(
子项:快照2.data.documents.map((DocumentSnapshot文档){
如果(文档['first_name']=='James'){
返回新的FindFollowerWidget(
名称:文档['first_name']+''+文档['last_name'],
用户名:文档['username'],
);
}
).toList(),
),
我的问题是:当文档快照字段具有特定值(在本例中,名字是“James”)时,如何仅返回FindFollowerWidget


谢谢!

我不太确定你在问什么。可能是什么方法


我不太确定你在问什么。可能是方法


对于哪个if语句,您使用了三个if语句。?remove
snapshot2.data!=null
。没有必要对@anmol.majhail进行编辑以增加清晰度。问题是关于ListView中的if语句。希望您能想到如何使其工作!使用ListView.builder您可以在itemBuilder中运行if语句。对于哪个if语句,您使用了三个if语句。?remove
snapshot2.data!=null
。没有必要对@anmol.majhail进行编辑以增加清晰度。问题是关于ListView中的if语句。希望您能想到如何使其工作!使用ListView.builder您可以在itemBuilder中运行if语句。
snapshot2.data.document
    .where((document)=>document["first_name"]=="James")
    .map((document)=>FindFollowerWidget(...))
    .toList();