如何显示Firebase用户列表(不包括在Flatter中登录的用户)?

如何显示Firebase用户列表(不包括在Flatter中登录的用户)?,firebase,flutter,dart,google-cloud-firestore,firebase-authentication,Firebase,Flutter,Dart,Google Cloud Firestore,Firebase Authentication,目前,我有一个SteamBuilder从“用户”集合获取数据 return ListView.builder( itemCount: snapshot.data.documents.length, itemBuilder: (context, index) { DocumentSnapshot document = snapshot.data.documents[index]; // else

目前,我有一个SteamBuilder从“用户”集合获取数据

return ListView.builder(
          itemCount: snapshot.data.documents.length,
          itemBuilder: (context, index) {
            DocumentSnapshot document = snapshot.data.documents[index];

            // else
            return user.uid == document['uid']
                ? null //null should not be returned but the user should be excluded in the below ListTile
                // this is causing only the users up to the logged-in user to display and then terminating without rendering other widgets

                : ListTile(
                    contentPadding: EdgeInsets.all(10),
                    title: Text(
                      document['name'],
                      style: TextStyle(
                          fontSize: 30,
                          fontWeight: FontWeight.bold,
                          fontStyle: FontStyle.italic),
                    ),
                  );
          });
    },
  ),
我应该实现什么逻辑才能将登录用户排除在渲染之外,但显示所有其他用户,我可以将where()传递给快照吗

我面临着同样的问题,但下面的示例代码给出了解决方案,我希望这对您有用

返回ListView.com(
itemBuilder:(上下文,索引){
回墨槽(
onTap:(){},
子:容器(
高度:snapshot.data.documents[index].data['id']!=uid
? 70.0
:0.0,//此行用于隐藏特定单元格。。。
宽度:MediaQuery.of(context).size.width,
子:列(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.max,
儿童:[
填充物(
填充:常数边集全部(8.0),
子:文本(快照)
.data.documents[index].data['昵称]])
],
)
],
),
),
);
},
separatorBuilder:(上下文,索引){
返回snapshot.data.documents[index].data['id']!=uid
?分隔器()
:Container();//此行隐藏特定单元格的设备。。
},
itemCount:snapshot.data.documents.length);
我面临着同样的问题,但下面的示例代码给出了解决方案,我希望这对您有用

返回ListView.com(
itemBuilder:(上下文,索引){
回墨槽(
onTap:(){},
子:容器(
高度:snapshot.data.documents[index].data['id']!=uid
? 70.0
:0.0,//此行用于隐藏特定单元格。。。
宽度:MediaQuery.of(context).size.width,
子:列(
mainAxisSize:mainAxisSize.max,
mainAxisAlignment:mainAxisAlignment.center,
儿童:[
划船(
mainAxisAlignment:mainAxisAlignment.start,
mainAxisSize:mainAxisSize.max,
儿童:[
填充物(
填充:常数边集全部(8.0),
子:文本(快照)
.data.documents[index].data['昵称]])
],
)
],
),
),
);
},
separatorBuilder:(上下文,索引){
返回snapshot.data.documents[index].data['id']!=uid
?分隔器()
:Container();//此行隐藏特定单元格的设备。。
},
itemCount:snapshot.data.documents.length);

那么您想显示所有未登录的用户吗?我想显示除当前登录用户之外的所有用户,我已经为集合(“用户”)中的每个用户创建了一个文档。我知道了运算符不能在where()方法中使用,因为它的伸缩性不好。因此,必须在本地进行更改。因此,我试图在不使Listview.builder()中的小部件树太复杂的情况下完成它。好吧,我不知怎么想出了一种完成任务的肮脏方法。我添加了一个bool=false变量并创建了一个列表。首先将快照添加到列表中,然后添加条件if(user.uid==document['uid']bool=true。然后生成bool?Contianer(高度:0):ListTile()抱歉,我一直处于脱机状态。有时完成一些复杂的功能可能会变得很难看,但也许您可以进行一个复合查询,以查看当前登录的用户。我不确定您如何检查当前登录的用户和未登录的用户,但您可以使用2
.where()
查询。例如,
db.where(“年龄”),“”,30)
。这将为您提供与不相等查询相同的结果。不确定这是否适用于上面的示例,但可能会引导您找到正确的方向,而不是null return empty container(),因为为空不会占用任何空间。因此,您想显示所有未登录的用户吗?我想显示除当前登录用户之外的所有用户,我已为集合(“用户”)中的每个用户创建了一个文档。我了解到!=运算符不能在where()中使用方法,因为它不能很好地扩展。所以更改必须在本地完成。所以我尝试在不使小部件树在DE Listview.builder()中复杂化的情况下执行此操作太多了。好吧,我不知怎的想出了一个完成任务的肮脏方法。我添加了一个bool=false变量并创建了一个列表。首先将快照添加到列表中,然后添加了一个条件if(user.uid==document['uid']bool=true。然后构建了bool?Contianer(高度:0):ListTile()抱歉,我一直处于脱机状态。有时完成一些复杂的功能可能会变得很难看,但也许您可以进行一个复合查询,以查看当前登录的用户。我不确定您如何检查当前登录的用户和未登录的用户,但您可以使用2
.where()
查询。例如,
db.where(“年龄”),“”,30)
。这将为您提供与不相等查询相同的结果。不确定这是否适用于上面的示例,但可能会引导您找到正确的方向,而不是返回空容器
return ListView.separated(
            itemBuilder: (context, index) {
              return InkWell(
                onTap: () {},
                child: Container(
                  height: snapshot.data.documents[index].data['id'] != uid
                      ? 70.0
                      : 0.0, // this line for hiding specific cell...
                  width: MediaQuery.of(context).size.width,
                  child: Column(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.center,
                    children: <Widget>[
                      Row(
                        mainAxisAlignment: MainAxisAlignment.start,
                        mainAxisSize: MainAxisSize.max,
                        children: <Widget>[
                          Padding(
                              padding: const EdgeInsets.all(8.0),
                              child: Text(snapshot
                                  .data.documents[index].data['nickname']))
                        ],
                      )
                    ],
                  ),
                ),
              );
            },
            separatorBuilder: (context, index) {
              return snapshot.data.documents[index].data['id'] != uid
                  ? Divider()
                  : Container(); // this line hide the devider for specific cell..
            },
            itemCount: snapshot.data.documents.length);