firebase - 方法 'document' 没有为类型 'CollectionReference' 定义。 flutter/火力基地

标签 firebase flutter document

没有为类型“CollectionReference”定义方法“document”。
尝试将名称更正为现有方法的名称,或定义名为“文档”的方法。
我在我的项目中收到此错误。你能帮助我吗?
我的代码:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:crypto_app/models/users.dart';

class FireStoreService {
  final FirebaseFirestore _firestore = FirebaseFirestore.instance;
  final DateTime time = DateTime.now();

  Future<void> createUser({id, mail, userName, photoUrl = ""}) async {
    await _firestore.collection("users").doc(id).set({
      "userName": userName,
      "mail": mail,
      "photoUrl": photoUrl,
      "about": "",
      "createTime": time
    });
  }

  Future<Users> bringUser(id) async {
    DocumentSnapshot doc = await _firestore.collection("users").doc(id).get();
    if (doc.exists) {
      Users users = Users.dokumandanUret(doc);
      return users;
    }
    return null;
  }

  void userUpdate({String userId, String userName, String photoUrl = ""}) {
    _firestore
        .collection("users")
        .document(userId)
        .updateData({"userName": userName, "photoUrl": photoUrl});
  }
}

最佳答案

CollectionReferencecloud_firestore对于 flutter/飞镖没有 document(..)方法。它叫doc(..)反而。 https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/CollectionReference/doc.html

关于firebase - 方法 'document' 没有为类型 'CollectionReference' 定义。 flutter/火力基地,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/67559567/

相关文章:

Javascript 重置 element.style

angular - 如何将可观察值存储在变量或属性中

android - 从 GCM 迁移到最新的 FCM 但获得相同的 token

flutter - RenderListWheelViewport对象在布局期间被赋予了无限大小

java - 使用 document.parse(string) 时获取 SAXException

angularjs - 在 Angular 中,$document.find ('body' ).eq(0) 与 $document[0].body

android - Firebase Storage - 在 Android 中上传多个图像文件

firebase - undefined 不是一个函数(正在评估 '_iterator2[typeof Symbol === "函数”

flutter - xcrun : error: invalid active developer path, problem after zsh update for flutter

flutter - 滚动 Controller animateTo()