没有为类型“CollectionReference”定义方法“document”,Flutter/Firebase

i7uq4tfw  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(147)

没有为类型“CollectionReference”定义方法“document”。请尝试将名称更正为现有方法的名称,或定义名为“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});
  }
}
mqkwyuun

mqkwyuun1#

flutter/dart的cloud_firestore中的CollectionReference没有document(..)方法。它被改为调用doc(..)https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/CollectionReference/doc.html

相关问题