【发布时间】:2020-07-12 23:13:25
【问题描述】:
我希望从 Firestore 中检索图像,以便在我的用户登录时将其存储在模型中。
我成功地将我的图像存储在 Firestore 上,我检索了图像 URL,并将该 URL 存储在 Firebase 上的用户集合中。
我的 User 在我的 Flutter 应用上有以下模型:
class User {
String userID;
File userImage;
String email;
String userName;
}
我在注册过程中使用相同的模型将我的用户信息上传到 Firebase。
我希望在我的用户登录时重用该模型。
检索我的用户信息后,我执行以下操作:
User _getUserInformation(String userID, Map<String, dynamic> userInformation) {
User userProfile = User(
userID: userID,
userImage: File.fromUri(userInformation["imageURL"]),//The problem is here
email: userInformation["email"],
userName: userInformation["userName"],
);
return userProfile;
}
我无法使用 URL 和方法 File.fromUri() 检索我的用户图像,因为 我需要将我的用户图像存储到 文件 类型变量,我需要从 URL 中获取图片并将其转换为 File 类型。
如何从 Firestore 中检索图像并将其转换为 文件 类型以将其存储在我的用户模型中?
或者有人对不同的方法有什么建议吗?我不希望将模型上的 userImage 字段更改为动态类型或 var 类型。
【问题讨论】: