查看代码:
final ref = FirebaseStorage.instance.ref().child('Posts');
ref.listAll().then((result) {
print("Hello: ${result}");
因此,在FirebaseStorage中,我创建了一个名为“帖子”的文件夹,并在其中手动上传了一些图像。现在,我以某种方式发现了如何打印Posts文件夹中的所有数据。
查看输出:
{prefixes: {}, pageToken: null, items: {header_of_grace_and_beauty_in_summer.jpg: {bucket: hello-465d1.appspot.com, path: /Posts/header_of_grace_and_beauty_in_summer.jpg, name: header_of_grace_and_beauty_in_summer.jpg}, header_of_style_statement_with_valvet.jpg: {bucket: hello-465d1.appspot.com, path: /Posts/header_of_style_statement_with_valvet.jpg, name: header_of_style_statement_with_valvet.jpg}, header_of_dazzling_monsoon.jpeg: {bucket: hello-465d1.appspot.com, path: /Posts/header_of_dazzling_monsoon.jpeg, name: header_of_dazzling_monsoon.jpeg},
因此,您可以看到Prefix,PageToken,item,bucket和name均为n。我想要这个列表的名字和getDownloadUrl。
我该怎么做?
至少有人可以给出答案并打印出来吗?我试过了,但是那没有发生。
编辑:
//Get 'Posts' stream
Stream<List<PostData>> get posts {
ref.listAll().then((value) {
print('VAL: $value');
return value;
});
}
这样我就可以访问:
final posts = Provider.of<List<PostData>>(context) ?? [];
pri("VALUE:-> $posts");
答案 0 :(得分:0)
initializing storage bucket
final FirebaseStorage storage =
FirebaseStorage(storageBucket: 'Bucket Name');
List<String> image=new List();
var images= ref['items'].keys.toList();
for (var i in images){
String filePath = 'post/i';
StorageReference imgref = storage.ref().child(filePath);
image.add(imgref.getDownloadURL());
}