这是我的挑战:
我正在使用来自https://firebase.flutter.dev/docs/storage/usage/的以下示例将图片从我的手机图库(它为我提供String filepath-variable)上传到我的FireBaseStorage。
Future<void> handleTaskExample2(String filePath) async {
File largeFile = File(filePath);
firebase_storage.UploadTask task = firebase_storage.FirebaseStorage.instance
.ref('uploads/picture-to-upload.jpeg')
.putFile(largeFile);
task.snapshotEvents.listen((firebase_storage.TaskSnapshot snapshot) {
print('Task state: ${snapshot.state}');
print(
'Progress: ${(snapshot.bytesTransferred / snapshot.totalBytes) * 100} %');
}, onError: (e) {
print(task.snapshot);
if (e.code == 'permission-denied') {
print('User does not have permission to upload to this reference.');
}
});
try {
await task;
print('Upload complete.');
} on firebase_core.FirebaseException catch (e) {
if (e.code == 'permission-denied') {
print('User does not have permission to upload to this reference.');
}
// ...
}
}实际上,一切都很好。我上传到我的存储中的图像显示在应用程序内的我的GridView中...
但是,如果我通过FireBase网站手动将图像上传到我的存储中,我的gridView (显示我存储中的图片的位置)不会自动更新。
但是,如果我更改屏幕并返回,则会显示手动上传的图片。
看起来我需要一个像StreamBuilder这样的东西,每当我的存储发生变化时,我的应用程序都会收到通知。
有没有人知道如何实现这个或任何其他想法来解决我的问题?
谢谢
发布于 2021-05-13 19:46:50
listAll和list只获取一次数据,所以不幸的是你不能在它们上面有一个流。这里有两个选项。
listAll,比如每隔2-3分钟listAll.这取决于你的用法,什么是最适合你的。
https://stackoverflow.com/questions/67516456
复制相似问题