Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
286 views
in Technique[技术] by (71.8m points)

firebase - How to structure data for flutter Cart flutter?

I am struggling with flutter ecommerce cart data structure for firebase , what is the right way to structure the data?

for now I am structuring it someting like this on firebase :

cart_items = [
        {
            "id": 144,
            "created_at": "2019-04-04 14:42:04",
            "updated_at": "2019-04-04 14:42:04",
            "cart_id": "3",
            "client_id": "83",
            "product_id": "6",
            "quantity": "1",
            "price": "1500",
            "name": "Cucumber (2Pcs)",
            "image": "products/es4eGjkgQ6MvzTaMyX4iXWjcSX03mVk3QB9oODWk.jpeg",
           },
        {
            "id": 145,
            "created_at": "2019-04-04 14:42:09",
            "updated_at": "2019-04-04 14:42:09",
            "cart_id": "3",
            "client_id": "83",
            "product_id": "5",
            "quantity": "1",
            "price": "2000",
            "name": "Cauliflower",
            "image": "products/lVZ31zORzltyVIDXhHoCWUgjTlal7cWd7pI8DL2V.jpeg",
            }
    ]

But the problem with this is I am not able to update the quantity field of the product.

question from:https://stackoverflow.com/questions/65902351/how-to-structure-data-for-flutter-cart-flutter

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

quantity field must be integer or number not string then you can use FieldValue.increment(itemCount) for updating quantity value also I see cart_id, client_id, product_id, price fields are also string change it to integer or number


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...