flutter - 过滤 Firestore 更新文档
问题描述
当我尝试更新文档时,我的应用程序不断崩溃。我究竟做错了什么?
Future<bool> updateEvent(data, id) async {
try {
final _ref = _db.collection('content').doc(id);
print(_ref);
await _ref.update(data);
return true;
} catch (error) {
print(error);
return false;
}
}
print(_ref)
返回
flutter: DocumentReference(content/KwaKlb1GpUbqSQd8K9rd)
data
是这样设置的
final data = {
"active": true,
"title": _titleTextController.text != null
? _titleTextController.text
: null,
...
};
解决方案
要正确回答,最好看到您的错误消息。我目前没有将 Firestore 与 Flutter 一起使用,但如果它在其他平台上像 Firestore 一样工作,它将不允许将 Null 值设置为字段。当文本为空时,这将在您的示例中发生。
推荐阅读
- c# - C# WPF if ComboBox Equal 多个条件
- c# - Web Api 控制器不写入文件
- reactjs - 在 Typescript React 中查找库组件类型的过程是什么?
- json - 通过数组中元素的已知值来搜索项
- html - 在 React 应用程序中鼠标悬停时不显示 aria-label
- javascript - 重新初始化骨干集合不会解除绑定事件
- asp.net-mvc - 找不到类型或命名空间名称“IndexModel”(您是否缺少 using 指令或程序集引用?)
- python - 从 python 中的 XML 字符串中删除命名空间和节点
- azure-data-factory - 使用 OAuth2 连接到 REST 端点
- git - 如何让 AWS CodeBuild 执行完整克隆?