Zan*_*ane 2 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,
),
);
}
Run Code Online (Sandbox Code Playgroud)
这将处理事务超时:
Firestore.instance.runTransaction((Transaction tx) {
// handle transaction here
}).timeout(Duration(seconds: 5), onTimeout: () {
// handle transaction timeout here
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2482 次 |
| 最近记录: |