Problem:
The problem was that firebase storage is too slow.
But I found an easy solution.
Solution:
You have to make your image into a network image
To do that complete these steps:
1. Get the URL of the image
To do that use this code:
var ref = FirebaseStorage.instance.ref().child("profileImages/${uid}_profile_picture.png");
// this is the URL of the image
String url = (await ref.getDownloadURL()).toString();
2. Save the URL
If you do it for something like profile images then add the URL to cloud firestore when you add the image and change the image and use this code:
await FirebaseFirestore.instance
.collection('users')
.where("uid", isEqualTo: FirebaseAuth.instance.currentUser?.uid)
.get()
.then((value) async {
await FirebaseFirestore.instance.collection('users').doc(value.docs[0].id).update({"profileImageURL": url});
});
If you do it for something like your app icon then use this code:
(await SharedPreferences.getInstance()).setString("logoURL", url);
3. Get the URL from an image
If you use the first way to save the URL(If you do it for something like profile images) then use this code:
await FirebaseFirestore.instance
.collection('users')
.where("uid", isEqualTo: uid)
.get()
.then((value) {
url = value.docs[0].data()["profileImageURL"];
});
If you do the other way to save the URL(if you do it for something like your app icon) use this code:
(await SharedPreferences.getInstance()).getString("logoURL");
4. Display the image
To display the image use this code:
Container(
height: 100,
width: 100,
child: Image(image: NetworkImage(url)),
);
Hope it helps!