gpt4 book ai didi

firebase - Flutter Firestore 设置超时

转载 作者:行者123 更新时间:2023-12-05 01:41:53 27 4
gpt4 key购买 nike

据我所知,当互联网连接中断时,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/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com