【发布时间】:2020-02-27 06:48:20
【问题描述】:
我正在尝试使用 Firestore 运行一个事务,该事务将增加一个投票计数器。 我正在运行以下代码:
Firestore.instance.runTransaction((Transaction tx) async {
DocumentSnapshot postSnapshot = await tx.get(postRef);
if (postSnapshot.exists) {
//print(postSnapshot.data['Votes']);
await tx.update(postRef, <String, dynamic>{'Votes': postSnapshot.data['Votes'] + 1})
.catchError((e) {print(e);});
}
}).catchError((e) {
print(e);
});
有时,这可以正常工作,但有时它会导致我的 android 模拟器静默崩溃 - 应用程序关闭并且控制台显示 Lost connection to device。 catchError 语句都不会打印,并且控制台没有输出。颤振医生报告没有问题。这在 iOS 上似乎不是问题,尽管由于错误是零星的,所以很难说。
我的 Flutter 版本是 Flutter (Channel stable, v1.12.13+hotfix.5, on Mac OS X 10.15.2 19C57, locale en-US)
有谁知道为什么会发生这种情况?这是颤振的问题还是我运行事务的方式有问题?任何帮助将不胜感激,谢谢!
【问题讨论】:
标签: android flutter dart google-cloud-firestore transactions