如何在Flutter中处理Firebase TimedOut异常

时间:2018-11-01 12:40:22

标签: firebase dart flutter google-cloud-firestore

我有一个页面,用于将一些数据发送到我的云firestore DB,当网络不慢时能够成功上传数据,但是当网络慢时我却收到超时异常,这在下面导致该应用程序崩溃

Exception has occurred.
PlatformException(Error performing transaction, Timed out waiting for Task, null)

我已经在这里执行了Internet adrress查找。我还尝试捕获运行事务方法上的错误以及使用timeOut方法。但似乎仍然无法解决这个问题。它仍然崩溃

    try {
       final result = await InternetAddress.lookup('google.com');
       if (result.isNotEmpty && result[0].rawAddress.isNotEmpty) {
           print('connected');
    Firestore.instance.runTransaction(((transactionHandler)async{
//some action Here
    }))..timeout(Duration(seconds: 10),onTimeout:(){
             scafoldKey1.currentState.showSnackBar(
            SnackBar(content: Text("oops, Transaction timed Out"),duration: Duration(seconds: 3),),
                      );

                                        });;
       }
     } on SocketException catch (_) {
        print('not connected');
     }

0 个答案:

没有答案