【发布时间】:2021-12-29 01:27:32
【问题描述】:
我的 Flutter 应用将接收来自用户的帖子。我的 swift 应用程序在我的 firebase firestore 数据库中有要替换的帖子。所以因为我在我的颤振获取帖子功能中有这个:
final userRef = FirebaseFirestore.instance.collection('users');
final QuerySnapshot result = await userRef.get();
result.docs.forEach((res) async {
print(res.id);
QuerySnapshot posts = await userRef.doc(res.id).collection("posts").get();
posts.docs.forEach((res) {
print(res.data());
});
});
因此,使用此功能,我可以打印每个用户发布的所有数据的列表。这是印刷品的一部分:
flutter: {postedDate: Oct 24, 2021 at 6:10 AM, id: twentyonepilots_354_1635073829.595439, caption: , likers: [], postUrlString: https://firebasestorage.googleapis.com:443/v0/b/globe-e8b7f.appspot.com/o/twentyonepilots%2Fposts%2Ftwentyonepilots_354_1635073829.595439.png?alt=media&token=48b6b1bc-112b-4d61-84ee-3847ba8dce94}
flutter: {postedDate: 13 Aug 2021, 9:54 AM, id: viktoria_923_1628837663.179892, caption: just posted, feeling good :), likers: [anelia, globetester, alis, devil, vladyynk, fllcuriie, HackerX, nihilistic, imherefromtiktok, donnasmithofficial, hhhh, sachiq], postUrlString: https://firebasestorage.googleapis.com:443/v0/b/globe-e8b7f.appspot.com/o/viktoria%2Fposts%2Fviktoria_923_1628837663.179892.png?alt=media&token=634ff70e-028c-4452-8c2b-b598eb8b8e48}
flutter: {postedDate: 21. Nov 2021 at 18:34, id: timsbs_464_1637516088.259705, caption: Hi https://google.com, likers: [timsbs], postUrlString: https://firebasestorage.googleapis.com:443/v0/b/globe-e8b7f.appspot.com/o/timsbs%2Fposts%2Ftimsbs_464_1637516088.259705.png?alt=media&token=4ce3bf4d-3187-4ee9-954a-dc39532694ae}
我怎样才能把这个列表变成这个帖子模型的列表?:
class Post {
String id = "";
String caption = "";
String postUrlString = "";
Timestamp postedDate = Timestamp.now();
Post(
{required this.id,
required this.caption,
required this.postUrlString,
required this.postedDate});
}
【问题讨论】:
标签: flutter google-cloud-firestore