From 9967caf0cddb81d536234cad3b3885a9a60ec3ce Mon Sep 17 00:00:00 2001
From: Moe <moe@chocola.dev>
Date: Tue, 26 Apr 2022 10:45:04 +0700
Subject: [PATCH] Add viewCart function

---
 lib/data/cart.dart | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/lib/data/cart.dart b/lib/data/cart.dart
index d07916f..0de34d5 100644
--- a/lib/data/cart.dart
+++ b/lib/data/cart.dart
@@ -38,4 +38,11 @@ Future<void> removeFromCart(productId, bool batch) async {
     }
   }
   await prefs.setString('cart', jsonEncode(cart).toString());
+}
+
+Future<dynamic> viewCart(productId, bool batch) async {
+  final prefs = await SharedPreferences.getInstance();
+
+  var cart = jsonDecode(prefs.getString('cart') ?? '[]');
+  return cart;
 }
\ No newline at end of file