firebase - Android 未捕获 Firestore 事务 PlatformException
问题描述
我在 Flutter 和 Firebase 中构建随机的 1:1 聊天应用程序。我transaction
用于将用户添加到聊天中,因为必须避免将超过 1 个用户的竞争条件添加到聊天中。聊天必须是 1:1。
如果超时,我需要捕获transaction
错误。transaction
但错误仅在 iOS(而非 Android)上捕获。仅在 iOS 上它会捕获错误,如下所示:
PlatformException(9,事务重试失败。:事务中读取的每个文档也必须写入该事务中。,null)
在调试模式下的 Android 上,应用程序冻结并抛出错误message_codecs.dart
:
throw PlatformException(代码:errorCode,消息:errorMessage,详细信息:errorDetails);
这是交易:
Future<bool> addUser() async {
try {
await Firestore.instance.runTransaction((transaction) async {
DocumentSnapshot chatRoomDocSnapshot =
await transaction.get(chatRoomDocRef);
bool userInChat = await chatRoomDocSnapshot[‘userInChat'];
if (userInChat == false) {
await transaction.update(chatRoomDocSnapshot.reference, {
‘userInChat': true,
});
}
});
await chatUserRef.setData({
‘User’: user,
});
userAdded = true;
} catch (e) {
print(e);
userAdded = false;
}
return userAdded;
}
我正在使用插件cloud_firestore: ^0.12.5+1
有人看到这个插件问题吗?
为什么只在 Android 上出现此错误?
感谢帮助!
解决方案
推荐阅读
- javascript - 在 DM 中删除 Bot 生成的消息
- spring - DataSourceTransactionManager API中“可能允许每个数据源一个线程绑定连接”是什么意思?
- php - Jenkins Mercurial 如何从构建中包含的所有变更集中获取所有文件
- python - 比较 3D 列表和 4D 列表
- perl - Perl:如何使用现有包作为新类/对象的基础
- flutter - 行内的容器对齐
- python - 我应该如何在 python 上编写这个程序?
- c# - 如何等到使用 selenium webdriver 加载 div 下拉列表?
- javascript - 甚至在用户在警报窗口上按下“确定”之前,Javascript 代码就会被执行
- linux - /usr/bin/ld 编译 Fortran 77 代码时出错