【发布时间】:2021-06-27 16:08:46
【问题描述】:
Future<void> downloadFiles(url) async {
var result = await getDirectories(url); //this function just returns the path in firestore storage
Directory appDocDir = await getApplicationDocumentsDirectory();
result.items.forEach((firebase_storage.Reference ref) async {
File downloadToFile = File('${appDocDir.path}/notes/${ref.name}');
try {
await firebase_storage.FirebaseStorage.instance
.ref(ref.fullPath)
.writeToFile(downloadToFile);
} on firebase_core.FirebaseException catch (e) {
print(e);
}
});
}
我在 Flutter 中创建了这个函数来循环浏览我的 Firebase 云存储中的文件。我尝试使用单个文件写入本地存储并且它可以工作但是当我循环通过文件列表写入本地存储时它不起作用,它甚至不会产生错误,代码只是停在“foreach " 它甚至不执行 try catch 块。 Flutter 中是否有将多个文件写入本地存储的特定功能?
【问题讨论】:
-
您可能需要将 await 放在 results.items.forEach 之前
-
试过了,报错。它是说“foreach”是“void”类型,所以它的值不能被使用
标签: android flutter dart mobile google-cloud-storage