列出来自相同 ID 的配置文件 5 次
发布时间:2022-07-21 19:41:51 221
相关标签:
我做了一个追随者名单。但它列出了来自同一 ID 的配置文件 5 次。如下图所示。我找不到解决方案。你能帮助我吗。我的代码如下...................................................... ..................................................... ..................................................... .....................
关注卡片
class _FollowCardState extends State {
List followList = [];
getdata() async {
List followers = [];
final currentUserSnapshot = await FirebaseFirestore.instance
.collection('users')
.doc(FirebaseAuth.instance.currentUser!.uid)
.get();
List followIds =
List.from(currentUserSnapshot.data()!['following']);
// loop through all ids and get associated user object by userID/followerID
for (int i = 0; i < followIds.length; i++) {
var followId = followIds[i];
var data = await FirebaseFirestore.instance
.collection('users')
.doc(followId)
.get();
followers.add(data);
}
setState(() => followList = followers);
}
@override
void initState() {
super.initState();
getdata();
}
@override
Widget build(BuildContext context) {
return SingleChildScrollView(
physics: NeverScrollableScrollPhysics(),
child: ListView.builder(
shrinkWrap: true,
itemCount: followList.length,
itemBuilder: (context, index) {
var followerItem = followList[index];
print('photoUrl');
return _buildFollowersCard(followerItem['photoUrl'],
followerItem['username'], followerItem['uid']);
}),
);
}
Widget _buildFollowersCard(String photoUrl, String username, String uid) {
return Container(
height: 70,
width: double.infinity,
color: mobileBackgroundColor,
child: Card(
child: Column(children: [
//Header
Container(
height: 40,
width: double.infinity,
padding: const EdgeInsets.symmetric(
vertical: 4,
horizontal: 16,
).copyWith(right: 0),
child: Row(
children: [
CircleAvatar(
radius: 16,
backgroundImage: NetworkImage(
photoUrl,
),
),
Expanded(
child: Padding(
padding: EdgeInsets.only(left: 8),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
TextButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
ProfileScreen(uid: uid)));
},
child: Text(
username,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white),
),
),
],
),
),
),
],
),
)
]),
),
);
}
}
Follow\u屏幕
class _FollowScreenState extends State {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
backgroundColor: mobileBackgroundColor,
centerTitle: true,
title: Image.asset(
'Resim/logo.png',
height: 50,
),
),
body: StreamBuilder(
stream: FirebaseFirestore.instance.collection('users').snapshots(),
builder: (context,
AsyncSnapshot<QuerySnapshot<Map<String, dynamic>>> snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
child: CircularProgressIndicator(),
);
}
return ListView.builder(
itemCount: snapshot.data!.docs.length,
itemBuilder: (context, index) => FollowCard(
snap: snapshot.data!.docs[index].data(),
),
);
},
),
);
}
}
特别声明:以上内容(图片及文字)均为互联网收集或者用户上传发布,本站仅提供信息存储服务!如有侵权或有涉及法律问题请联系我们。
举报