Reputation: 65
I'm looking to retrieve an image from Firestore, to store it on a model when my user logs in.
I successfully stored my image on Firestore, and I retrieved the image URL, and stored the URL on my Users Collection on Firebase.
I have the following model for my User on my flutter App:
class User {
String userID;
File userImage;
String email;
String userName;
}
I use that same model to upload my user information to firebase during the Signup process.
I'm looking to reuse that model for when my user logs in.
After retrieving my user information I do the follow:
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;
}
I cannot retrieve my user image using the URL and the method File.fromUri(), because I need to store my user image into a File type variable, I need to get the image from the URL and convert it into a File type.
how to retrieve an image from Firestore and convert it into a File type to store it on my User model?
Or does someone have any suggestion about a different approach? I would prefer not to change my userImage field on my model into a dynamic type or a var type.
Upvotes: 1
Views: 254
Reputation: 192
You can use the CachedNetworkImage: Cached network Image like this:
CachedNetworkImage(
imageUrl: yourUrl,
imageBuilder: (context, imageProvider) =>
Container(
height: 36,
width: 36,
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: imageProvider,
fit: BoxFit.cover,
),
),
),
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(LineIcons.exclamation),
);
Upvotes: 1