firebase - Flutter Firestore 设置超时

标签 firebase flutter google-cloud-firestore

据我所知,当互联网连接中断时,Flutter Firestore 操作将继续重试。有没有办法设置超时持续时间,以便 Firestore 在超过超时持续时间时在 CatchError 中抛出错误?

最佳答案

试试这个来处理应用程序初始化时的超时:

  Future<FirebaseApp> app;
  void appInit() {
    app.timeout(Duration(seconds: 5), onTimeout: (){
      // handle app timeout here
    });
    app = FirebaseApp.configure(
      name: 'test',
      options: const FirebaseOptions(
        googleAppID: googleAppID,
        gcmSenderID: projectID,
        apiKey: apiKey,
        projectID: projectID,
      ),
    );
  }

这将处理事务超时:

Firestore.instance.runTransaction((Transaction tx) {
  // handle transaction here
}).timeout(Duration(seconds: 5), onTimeout: () {
  // handle transaction timeout here
});

关于firebase - Flutter Firestore 设置超时,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52984257/

相关文章:

ios - Firebase 后台和非事件通知不显示 iOS

Flutter)我正在使用 Riverpod,但我的代码找不到 ConsumerStatefulWidget

flutter - SharedPreferences.getInstance() 总是返回 null

flutter - 如何在flutter中重新加载网络图像?

android - 优化 firestore querysnapshot 监听器以在 android 中读取

java - 编译未能完成 :Program type already present: com. google.android.gms.internal.measurement.zzabn

ios - Firebase 和后台运行的预定通知

firebase - 从 Cloud Firestore 获取所有用户的所有帖子

javascript - 如何在 native react 中显示两个 Firestore 集合中的数据

javascript - 将 documentId 存储为文档中的字段