![](/img/trans.png)
[英]How to save the document id in document field while creating it in Flutter Firebase
[英]how to get seller id and product id in flutter firebase in one field for example, product field
FirebaseFirestore.instance
.collection('products')
.add({
// how to add product id and seller id
'image': imageUrls,
'name': name,
'category': category,
'description': description,
'price': 'RM' + ' ' + price,
'weight': weight + 'gram',
'stock': stock,
}).then((value) {
当卖家将他们的产品添加到我的 stream 生成器的卖家主页时,我不知道如何声明差异卖家。 此外,在下面的映射中声明卖家 ID 和产品 ID,将数据添加到 firebase
您可以生成一个新的随机产品 ID,对于卖家 ID,您可以使用添加产品的卖家的用户 ID。
FirebaseAuth firebaseAuth = FirebaseAuth.instance;
FirebaseFirestore firebaseFirestore = FirebaseFirestore.instance;
CollectionReference collectionReference = firebaseFirestore.collection('products');
String docID = collectionReference.doc().id;
collectionReference.doc(docID).set({
'productID': docID,
'sellerID': firebaseAuth.currentUser!.uid, //(it is the userID of the seller who is adding this product)
'image': imageUrls,
'name': name,
'category': category,
'description': description,
'price': 'RM' + ' ' + price,
'weight': weight + 'gram',
'stock': stock,
}).then((value) {
// write your other logic here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.