如何在flutter上为firestore写入超时



当我在没有互联网连接的情况下更新消防仓库数据时。它只是粘在那里。如何使消防仓库请求超时。或者最好的方法是什么?

try {
await userRef.document(uid).updateData({ 
"data": data 
});
return Response.isSuccess({});
} catch(err) {
print(err);
return Response.isError(err);
}

firestore中存在超时方法。

await userRef.document(uid).updateData({ 
"data": data 
}).timeout(Duration(seconds: 1));

尝试使用事务,可以设置超时持续时间。

await Firestore.instance.runTransaction((Transaction tx) {
await tx.get / set / update 
}).timeout(Duration(seconds: 1), onTimeout: () {
print('Timed out');
});

最新更新