when I upload an Image using firebase storage, it doesn't show in the screen until I do hot refresh. So the question is: How to show it automatically when I pick it either from the gallery or the camera? Thanks.
Codes:
late File file;
var imagePicker = ImagePicker();
var imgUrl;
var refStorage;
uploadPosterImage() async {
var pickedImage = await imagePicker.getImage(source: ImageSource.gallery);
if (pickedImage != null) {
setState(() {
file = File(pickedImage.path);
});
var imageName = basename(pickedImage.path);
var rand = Random().nextInt(10000000);
imageName = "$rand$imageName"; // random number + image name
refStorage = FirebaseStorage.instance.ref("items/$imageName");
await refStorage.putFile(file);
imgUrl = await refStorage.getDownloadURL();
}
}
------- and that's the code in the body:
Container(
margin: EdgeInsets.only(bottom: 10),
height: 230,
width: 160,
decoration: BoxDecoration(
border: Border.all(color: Colors.yellow),
borderRadius: BorderRadius.circular(20)),
child:
//imgUrl==null?
InkWell(
onTap: ()async{
await uploadPosterImage();
},
child: imgUrl == null? _icon : Image(image: NetworkImage(imgUrl),) )
),

