英文:
How to display a list of Firebase users excluding the logged-in user in flutter?
问题
目前,我有一个SteamBuilder从“user”集合中获取数据。
return ListView.builder(
itemCount: snapshot.data.documents.length,
itemBuilder: (context, index) {
DocumentSnapshot document = snapshot.data.documents[index];
// 否则
return user.uid == document['uid']
? null //null不应该返回,但是应该排除在下面的ListTile中
// 这导致只显示到已登录用户的用户,然后终止而不呈现其他小部件
: ListTile(
contentPadding: EdgeInsets.all(10),
title: Text(
document['name'],
style: TextStyle(
fontSize: 30,
fontWeight: FontWeight.bold,
fontStyle: FontStyle.italic),
),
);
});
},
),
我应该实现什么逻辑以排除已登录用户的渲染,但显示所有其他用户,我可以将一个where()传递给snapshot吗?
英文:
Currently, I have a SteamBuilder fetching data from a "user" collection
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),
),
);
});
},
),
What logic should I implement so I exclude the logged-in user from rendering but display all others, can I pass a where() to the snapshot?
答案1
得分: 0
以下是您要翻译的内容:
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,
);
英文:
> I am facing the same problem but here is the solution in below sample code I hope this will work for you.
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);
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论