更新时间:2023-01-15 11:39:02
我认为您的引用中包含的.ref()和thesnapshot.data()['image'].toString().
尝试这样的事情
Future< void>downloadURLExample()异步{字符串downloadURL =等待firebase_storage.FirebaseStorage.instance.ref('users/123/avatar.jpg').getDownloadURL();
i have been trying to get the download URL for my images in firebase storage so I can add it to my listview builders "NetworkCatched Images" for each of my items in the list, as you can see from my code below, I first declared a variable at the beginning of my stateful class called "URL" so I could change the value by making it equal to the download URL i get from firebase storage, but it seems like the async function I'm using doesn't even run because i made sure it prints out the value of the downloaded URL after it is done, but i see nothing in my debug console, where am going wrong here?
i keep getting this error No object exists at the desired reference.
by the way, the "thesnapshot.data()['image']"
in my code is equal to the name of the image file e.g books.jpg
which is the exact name of the file and it is in a folder called category as you can see below, would really appreciate some enlightenment on this, thanks
class Home extends State<HomeScreen> {
var url;
ListView.builder(shrinkWrap: true, padding: EdgeInsets.all(0), physics: NeverScrollableScrollPhysics(), itemCount: snapshot.data.documents.length, itemBuilder: (BuildContext context, int index)
{
DocumentSnapshot thesnapshot = snapshot.data.docs[index];
current_category = thesnapshot.data()['category'];
printUrl() async {
Reference ref = FirebaseStorage.instance.ref().child("category/" + thesnapshot.data()['image'].toString());
var togo = (await ref.getDownloadURL()).toString();
setState(() {
url = togo;
print(url);
});
}
printUrl();
I think that the .ref() included in your reference doesn't go thereas well as the thesnapshot.data()['image'].toString().
Try something like this
Future<void> downloadURLExample() async {
String downloadURL = await firebase_storage.FirebaseStorage.instance
.ref('users/123/avatar.jpg')
.getDownloadURL();
Extracted from the documentation