Following is the sample of my data class to add product details to the Firestore
, I wanted to add Firebase
timestamp to know when the item was added. Even though I do not know how to do it, I tried to like the following but I am getting an error.
Note: I know how to add Timestamp to Firestore
and I have done that using "timestamp" to FieldValue.serverTimestamp()
when adding a Hashmap
. I am having trouble when it's part of an object of my data class.
@Parcelize
data class Product(
val user_id: String = "",
val mrp: String= "0.00",
val price: String = "0.00",
val description: String = "",
val stock_quantity: String = "",
val image: String = "",
val product_added_date: FieldValue? = null,
) : Parcelable
The object of the product to add to Firestore
.
val product = Product(
FirestoreClass().getCurrentUserID(),
et_product_mrp.text.toString(),
et_product_price.text.toString(),
et_product_description.text.toString().trim { it <= ' ' },
et_product_quantity.text.toString().trim { it <= ' ' },
mProductImageURL!!,,
et_product_delivery_charge.text.toString().trim { it <= ' ' },
imageURL.size,
FieldValue.serverTimestamp(),
)