From ee2384595aaac19bd4f0660713fc4d7f65a93f42 Mon Sep 17 00:00:00 2001 From: Moe Poi ~ Date: Fri, 10 Nov 2023 21:52:25 +0700 Subject: [PATCH] Empty cart after checkout --- lib/components/checkout_form.dart | 2 ++ lib/data/cart.dart | 6 ++++++ 2 files changed, 8 insertions(+) diff --git a/lib/components/checkout_form.dart b/lib/components/checkout_form.dart index 3d90865..b42e752 100644 --- a/lib/components/checkout_form.dart +++ b/lib/components/checkout_form.dart @@ -61,6 +61,8 @@ class _CheckoutFormState extends State { "data": cartData, }; + await clearCart(); + var statusCode = await loadCheckout(data); return statusCode; } diff --git a/lib/data/cart.dart b/lib/data/cart.dart index c51619e..960e74d 100644 --- a/lib/data/cart.dart +++ b/lib/data/cart.dart @@ -37,6 +37,12 @@ Future removeFromCart(productId, bool batch) async { box.put('cart', jsonEncode(cart).toString()); } +Future clearCart() async { + final box = Hive.box(); + + box.put('cart', '[]'); +} + Future viewCart() async { final box = Hive.box();