首页 > 解决方案 > 过滤 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,
  ...
};

标签: fluttergoogle-cloud-firestore

解决方案


要正确回答,最好看到您的错误消息。我目前没有将 Firestore 与 Flutter 一起使用,但如果它在其他平台上像 Firestore 一样工作,它将不允许将 Null 值设置为字段。当文本为空时,这将在您的示例中发生。


推荐阅读