【发布时间】:2020-10-28 13:59:31
【问题描述】:
自上次flutter升级Flutter 1.22.2
Future uploadImageToStore(path, {String remotePath = "receiptImages"}) async {
Io.File _image = Io.File(path);
String fileName = Path.basename(_image.path);
print("uploadImageToStore " + path);
if (await _image.exists()) {
final Reference storageReference =
FirebaseStorage.instance.ref().child(remotePath + "/" + fileName);
final UploadTask uploadTask = storageReference.putFile(_image);
return uploadTask;
} else {
print("image does not exit");
}
}
它不返回UploadTask,而是返回TaskSnapshot
使用此方法的代码使用UploadTask 设置监听器:
final UploadTask uploadTask = await this.uploadImageToStore(
newReceipt['mergedImgPath']['path'],
remotePath: "receiptMergedImage");
uploadTask.events.listen((event) async {
this.updateReceiptProgress(event, newReceipt.key, receiptBloc);
});
以前版本的代码,现在可以编译但抛出运行时异常:
Unhandled Exception: type 'TaskSnapshot' is not a subtype of type 'UploadTask'
如何解决此问题以使用新的颤振版本?
【问题讨论】:
标签: flutter