【问题标题】:SetOptions not working in Firestore Flutter WEBSetOptions 在 Firestore Flutter WEB 中不起作用
【发布时间】:2020-04-08 04:23:53
【问题描述】:

查看 Flutter Web。似乎 Firestore Flutter Web 集成还没有完全实现。 试图传递 {merge: true} 参数:

webFirestore
    .collection("/users")
    .doc(uid)
    .set(map, {merge: true});

{merge: true} 带有红线下划线。尝试了不同的格式,没有工作。 有谁知道语法需要是什么样的?

Firestore 文档是这样说的:

/// An object to configure the [WriteBatch.set] behavior.
/// Pass [: {merge: true} :] to only replace the values specified in
/// the data argument. Fields omitted will remain untouched.
@anonymous
@JS()
abstract class SetOptions {
  /// Set to true to replace only the values from the new data.
  /// Fields omitted will remain untouched.
  external bool get merge;
  external set merge(bool v);
  external factory SetOptions({bool merge});
}

【问题讨论】:

  • 不带括号试试看。
  • 像这样:.set(map, merge: true);?不工作表示未定义命名参数合并
  • 你在使用这个firebase 包吗? cloud_firestore 包不支持 Flutter for web。
  • 我使用 'package:firebase/firebase.dart' 作为 WebFirebase; 'package:firebase/firestore.dart' 作为 WebFirestore; - [this] (medium.com/multiverse-software/…) 解决方法
  • 你提到用括号的时候用红线划了下划线,是什么错误?

标签: flutter google-cloud-firestore flutter-web


【解决方案1】:

遇到同样的问题,我相信这可行:

webFirestore
    .collection("/users")
    .doc(uid)
    .set(map, SetOptions(merge: true));

【讨论】:

    【解决方案2】:

    试试这个就行了

    firestoreInstance.collection("users").doc(firebaseUser.uid).set(
      {
       "username" : "userX",
      },SetOptions(merge: true))
    

    谢谢

    【讨论】:

      猜你喜欢
      • 2022-01-24
      • 2021-02-13
      • 2020-08-18
      • 2021-08-27
      • 1970-01-01
      • 2020-01-19
      • 2019-12-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多