Firebase 如何使用Flatter从cloud firestore中删除特定文档?
我需要使用存储在CloudFireStore中的Flatter操作数据的帮助。我已经创建了一个功能,它可以在按下图标时添加数据,在点击图标2次时删除数据 这是我的密码:Firebase 如何使用Flatter从cloud firestore中删除特定文档?,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,我需要使用存储在CloudFireStore中的Flatter操作数据的帮助。我已经创建了一个功能,它可以在按下图标时添加数据,在点击图标2次时删除数据 这是我的密码: void switcherIsFavSalon() async { var firebaseUser = await FirebaseAuth.instance.currentUser(); var docRef = Firestore.instance .collection('customers')
void switcherIsFavSalon() async {
var firebaseUser = await FirebaseAuth.instance.currentUser();
var docRef = Firestore.instance
.collection('customers')
.document(firebaseUser.uid)
.collection('favSalons');
if (isFavSalon == false) {
setState(() {
favIcon = 'assets/icons/heart_filled.png';
isFavSalon = true;
docRef.add({
"salonName": widget.salonName,
"workTime": widget.workTime,
"location": widget.location,
"rating": widget.rating
// here is add method
});
});
} else {
setState(() {
favIcon = 'assets/icons/heart_border.png';
isFavSalon = false;
docRef. //i need delete method here
});
}
}
有人能帮我吗,因为我是新来的。有一个错误,说列表不能分配给ParameterId type Futute,我能做什么?现在它说QuerySnapshot不能分配给列表进行了更多的编辑。如果在docList中工作,请告知我getter“data”未为“Future”类型定义。不能将“QuerySnapshot”类型的值分配给“Future”类型的变量。这个呢
void switcherIsFavSalon() async {
var firebaseUser = await FirebaseAuth.instance.currentUser();
var docRef = Firestore.instance
.collection('customers')
.document(firebaseUser.uid)
.collection('favSalons');
if (isFavSalon == false) {
setState(() {
favIcon = 'assets/icons/heart_filled.png';
isFavSalon = true;
await docRef.add({
"salonName": widget.salonName,
"workTime": widget.workTime,
"location": widget.location,
"rating": widget.rating
// here is add method
});
});
} else {
setState(() {
favIcon = 'assets/icons/heart_border.png';
isFavSalon = false;
});
docRef=await Firestore.instance.collection('customers').document(firebaseUser.uid)
.collection('favSalons');
await docRef.getDocuments().then((value) {
value.documents.forEach((element) {
if(element['salonName']==widget.salonName)
await docRef.document(element.documentID).delete();
});
});
}