不能';无法在新的Flatter firebasefirestore中完成查询
我尝试运行此代码以获取FirebaseFirestore中对象中存储的值。但是没有得到任何输出 有人能帮我从Firestore数据库中获取特定字段吗 字符串val=FirebaseFirestore.instance .collection('用户') .doc(“$userId”) .get() .toString() 瓦尔回来了 闭包:()=>函数“数据”的映射:不能';无法在新的Flatter firebasefirestore中完成查询,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我尝试运行此代码以获取FirebaseFirestore中对象中存储的值。但是没有得到任何输出 有人能帮我从Firestore数据库中获取特定字段吗 字符串val=FirebaseFirestore.instance .collection('用户') .doc(“$userId”) .get() .toString() 瓦尔回来了 闭包:()=>函数“数据”的映射: 我还尝试添加fieldpath(“displayName”和displayName)来获取。两者都显示错误。Firestore的
我还尝试添加fieldpath(“displayName”和displayName)来获取。两者都显示错误。Firestore的所有查询本质上都是异步的
get()
函数的返回类型是未来的
要获得实际值,您应该等待异步调用完成,然后您就可以处理数据了
像这样的
FirebaseFirestore.instance
.collection('users')
.doc("$userId")
.get()
.then()((DocumentSnapshot data) {
print(data);
print(data['displayName');
});
谢谢!现在可以了!