没有为类型“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});
}
}
1条答案
按热度按时间mqkwyuun1#
flutter/dart的
cloud_firestore
中的CollectionReference
没有document(..)
方法。它被改为调用doc(..)
。https://pub.dev/documentation/cloud_firestore/latest/cloud_firestore/CollectionReference/doc.html