Android 为什么文档更改在第一次尝试时没有保存在Firestore中?
我正在开发一个处理二维码生成和扫描的应用程序,一旦二维码被扫描,我将尝试将用户详细信息保存在firestore中。这里的问题是,第一次扫描时,细节没有保存在firestore中,在扫描二维码两次时,细节会被保存。有人能告诉我我在代码中哪里做错了吗 代码如下:Android 为什么文档更改在第一次尝试时没有保存在Firestore中?,android,firebase,flutter,dart,google-cloud-firestore,Android,Firebase,Flutter,Dart,Google Cloud Firestore,我正在开发一个处理二维码生成和扫描的应用程序,一旦二维码被扫描,我将尝试将用户详细信息保存在firestore中。这里的问题是,第一次扫描时,细节没有保存在firestore中,在扫描二维码两次时,细节会被保存。有人能告诉我我在代码中哪里做错了吗 代码如下: classesAttended = await FirebaseFirestore.instance .collection('students') .doc(ui
classesAttended = await FirebaseFirestore.instance
.collection('students')
.doc(uid)
.get()
.then((doc) async {
Map<String, dynamic> stuMap = await doc.data();
print("$stuMap fierstly");
if (!stuMap.containsKey('Attendance')) {
print("Hrllo");
await student_details.doc(uid).set({
'Attendance': {'$subject': 1}
}, SetOptions(merge: true));
print("$stuMap Inside");
} //after this if the doc.data() should get updated
Map<String, dynamic> stuMap2 = await doc.data(); // here this is returning null
print("${doc.data().toString()} is the docdata"); // i think from here execution doesnt takes place
print("$stuMap2 after adding");
stuMap2 = await doc.data()['Attendance'];
print("$stuMap2 secondly");
if (!stuMap2.containsKey(subject)) {
await student_details.doc(uid).set({
'Attendance': {'$subject': 1}
}, SetOptions(merge: true));
}
var val = await doc.data()['Attendance']['$subject'];
return val;
//return value.data()['noOfClassesAttended'];
});
classesAttended=wait FirebaseFirestore.instance
.collection(‘学生’)
.doc(uid)
.get()
.then((doc)异步{
Map stuMap=wait doc.data();
打印($stuMap firestly);
如果(!stuMap.containsKey('Attention')){
印刷品(“Hrllo”);
等待学生详细信息。文档(uid)。设置({
'出席人数':{'$subject':1}
},SetOptions(合并:true));
打印($stuMap内);
}//在此之后,如果应该更新doc.data()
Map stuMap2=wait doc.data();//这里返回null
print(${doc.data().toString()}是docdata”);//我认为从这里不会执行
打印(“添加后的$stuMap2”);
stuMap2=wait doc.data();
打印($stump2);
如果(!stuMap2.containsKey(主题)){
等待学生详细信息。文档(uid)。设置({
'出席人数':{'$subject':1}
},SetOptions(合并:true));
}
var val=wait doc.data();
返回val;
//返回值.data();
});
有人能解决这个问题吗?