【发布时间】:2021-10-14 12:57:39
【问题描述】:
我一直试图让用户按下按钮将他/她的图像上传到 Firebase 存储。它起作用了,因为我打印了结果。
flutter: https://firebasestorage.googleapis.com:443/v0/b/libraryapp-a805e.appspot.com/o/userPFP%2FIMG_0008.JPG?alt=media&token=fee1f918-5608-467d-8889-0f22853f02b1
这是函数的代码:
Future uploadFile() async {
if (file == null)
return;
else {
final fileName = Path.basename(file!.path);
final destination = 'userPFP/$fileName';
var task = DatabaseServices.uploadFile(destination, file!);
if (task == null)
return;
else {
final snapshot = await task.whenComplete(() {});
final urlDownload = await snapshot.ref.getDownloadURL();
imageUrl = urlDownload;
print(imageUrl);
}
}
}
当我按下一个按钮时,我调用了这个函数,这个:
child: TextButton(
onPressed: () async {
selectFile();
uploadFile();
print(
'File Selected Succesful');
},
但图像不会立即显示。我必须关闭表单,然后再次打开它,然后图像显示。但我希望每次按下该按钮时都显示图像。
任何帮助表示赞赏!谢谢。
【问题讨论】:
标签: firebase flutter dart firebase-realtime-database google-cloud-storage