![](/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.