![](/img/trans.png)
[英]How to display all images from firebase storage on React Native app?
[英]How to fetch all images from a folder in Firebase Storage?
我正在開發一個故事視圖應用程序,在該應用程序中,我在 firebase 存儲中創建了一個“故事”文件夾,在該文件夾下有一個帶有“用戶 ID”和用戶 ID 的文件夾,我存儲了相應用戶的所有故事。
現在,我正在嘗試獲取相應用戶的所有這些故事。 這是我用來獲取圖像的 function 但它給了我錯誤“圖像無法加載”
String storyUrl = " ";
void fetchstory() async {
final ref = FirebaseStorage.instance.ref().child('stories');
ref.listAll().then((value1) {
value1.items.forEach((folder) {
folder.listAll().then((value2) {
value2.items.forEach((stories) {
stories.getDownloadURL().then((value) {
storyUrl = value;
});
});
});
});
});
}
嘗試像這樣添加 await 和 setState
await stories.getDownloadURL.then((value){setState({storyUrl = value;});});
確保將故事數據類型更改為列表,因為您想獲取所有數據而不是一個故事,就像這樣
list<String> stories = "";
await stories.getDownloadURL.then((value){setState({storyUrl.add(value);});});
該值應該是一個字符串列表,因為您正在循環它
List<String> storyUrl = [];
void fetchstory() async {
final ref = FirebaseStorage.instance.ref().child('stories');
ref.listAll().then((value1) {
value1.items.forEach((folder) {
folder.listAll().then((value2) {
value2.items.forEach((stories) {
stories.getDownloadURL().then((value) {
storyUrl.add(value);//additems like this
setState((){});
});
});
});
});
});
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.