【问题标题】:Flutter: Changing firebase realtime database code to cloud firestore codeFlutter:将 Firebase 实时数据库代码更改为 Cloud Firestore 代码
【发布时间】:2021-01-09 16:57:41
【问题描述】:

我试图将以下 Flutter Firebase 实时数据库代码更改为 Cloud Firestore,但出现此错误...

  1. 错误:没有为“查询”类型定义“子”方法。
  2. 错误:没有为“查询”类型定义“推送”方法。
DatabaseReference databaseReference = FirebaseDatabase.instance.reference().child('Products');          

String uploadId = databaseReference.push().key;
HashMap map = new HashMap();
map['productName'] = productName;
map['productCat'] = selectedCat;
map['startingPrice'] = int.parse(startingPrice);
map['gapPrice'] = int.parse(gapPrice);
map['imageSrc'] = url;
map['timeStamp'] = DateTime.now().toString();

databaseReference.child(uploadId).set(map);

【问题讨论】:

    标签: flutter firebase-realtime-database google-cloud-firestore


    【解决方案1】:

    那是因为这不是您使用 Cloud Firestore 添加文档的方式。请看this参考添加文档。

    您的示例如下所示:

    final products = Firebase.instance.collection('products');
    products.add({
      'productName': productName,
      ...
    });
    

    【讨论】:

      猜你喜欢
      • 2020-07-24
      • 2019-08-07
      • 1970-01-01
      • 1970-01-01
      • 2019-10-12
      • 2022-01-21
      • 2015-09-22
      • 1970-01-01
      • 2018-03-15
      相关资源
      最近更新 更多