【发布时间】:2020-07-01 23:57:35
【问题描述】:
我的功能在下面,我把错误屏幕截图放在它下面。我尝试了很多东西,但找不到优雅和正确的方法来实现这一点。感谢您的帮助。
**It works**
Future<List<UserLike>> getUserLikedPosts() async {
return userCollection
.document(_currentUserId)
.collection(collection_like)
.limit(POST_LOAD_LIMIT)
.getDocuments()
.then(
(snapshot) {
if (snapshot == null) return null;
return snapshot.documents
.map((userImage) =>
UserLike.fromEntity(UserLikeEntity.fromSnapshot(userImage)))
.toList();
},
);
}
**It does not work**
Future<List<UserLike>> getUserLikedPosts() async {
return userCollection
.document(_currentUserId)
.collection(collection_like)
.limit(POST_LOAD_LIMIT)
.getDocuments()
.then(
(snapshot) {
if (snapshot == null) return null;
return snapshot.documents.map((userImage) async {
final postEntity =
UserLike.fromEntity(UserLikeEntity.fromSnapshot(userImage));
// NEED TO GET DOWNLOAD URL AND UPDATE MY OBJECT
final downloadUrl = await FirebaseStorage.instance
.ref()
.child("user/${post.userId}/post/${post.file}")
.getDownloadURL();
return postEntity.copyWith(downloadUrl: downloadUrl);
}).toList();
},
);
}
【问题讨论】: