首页 > 解决方案 > 为什么颤振不捕捉firebase存储文件未找到错误?

问题描述

在我的颤振应用程序中,我尝试在 firebase 存储中获取文件的 url。我故意删除了此文件,以测试在找不到文件时向用户显示的错误消息。问题是 Flutter/Dart 根本没有发现错误!相反,它会冻结应用程序,并在 Visual Studio 代码中显示此异常:

“发生异常。PlatformException(PlatformException(download_error,该位置不存在对象。,null))”

这是我捕获错误的代码:

StorageReference storageReference = FirebaseStorage.instance.ref().child('nonExistingFile.jpg');
storageReference.getDownloadURL().catchError((onError){
  scaffoldKey.currentState.showSnackBar(new SnackBar(content: new Text("Error: File not found!"), duration: new Duration(seconds: 4),));
});

上面的代码没有捕捉到错误并采取相应的行动!这是为什么??

标签: firebaseflutterdartfirebase-storage

解决方案


推荐阅读