I'm using ImagePicker to select a profile picture, once picture selected it'll be assigned to a Circle Avatar now how can I upload the picture into firebase. If the user refreshes the page(UI) Circle Avatar goes back to the default image! I need to replace the Circle Avatar with the currentUser's picture.
simply I don't know how to retrieve the image from firebase and assign it into Circle Avatar
Here's how I'm trying to update the circle avatar -
CircleAvatar(
radius: 30.0,
backgroundColor: Colors.white,
child: (_imageFile != null)
? Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
image: FileImage(_imageFile),//Selected Image
fit: BoxFit.fill),
),
)
: Image.network(
(photoUrl == null)
? 'https://www.materialui.co/materialIcons/image/add_a_photo_black_36x36.png'//Default Picture
: photoUrl,
fit: BoxFit.fill,
), //Replace with Image From DB
Uploading the picture -
Future UpdatePic() async{
String fileName = basename(_imageFile.path);
StorageReference firebaseStorageRef =
FirebaseStorage.instance.ref().child(fileName);
StorageUploadTask uploadTask = firebaseStorageRef.putFile(_imageFile);
StorageTaskSnapshot taskSnapshot = await uploadTask.onComplete;
showInSnackBar("Picture updated successfully.");
}
This uploads the picture but I don't know how to retrieve this into Circle Avatar of that particular user's profile.
photoUrl? You already have a file reference you can use to show an image. - Christopher MooreCircle Avatar(reference needs to be the file of currentUser). - Pranavan_imageFile. It's the same file you're uploading. There isn't a need to waste resources performing a read from storage if you already have the file. - Christopher Moore