diff --git a/cart.png b/cart.png deleted file mode 100644 index c528126..0000000 Binary files a/cart.png and /dev/null differ diff --git a/lib/components/search_box.dart b/lib/components/search_box.dart index 7eb6558..9d632e4 100644 --- a/lib/components/search_box.dart +++ b/lib/components/search_box.dart @@ -56,6 +56,7 @@ class SearchBox extends StatelessWidget { color: primaryColor, ), ), + showBadge: cartData.cartItems.isNotEmpty ? true:false, child: const Icon( Icons.shopping_bag_outlined, size: 30, diff --git a/lib/models/cart.dart b/lib/models/cart.dart index 373a045..0af068c 100644 --- a/lib/models/cart.dart +++ b/lib/models/cart.dart @@ -1,5 +1,6 @@ class CartItem { final String id; + final dynamic docId; final String prodId; final String prodName; final String prodImgUrl; @@ -9,6 +10,7 @@ class CartItem { CartItem({ required this.id, + required this.docId, required this.prodId, required this.prodName, required this.prodPrice, diff --git a/lib/providers/cart.dart b/lib/providers/cart.dart index 5e878c2..9847432 100644 --- a/lib/providers/cart.dart +++ b/lib/providers/cart.dart @@ -35,6 +35,7 @@ class CartData extends ChangeNotifier { void addToCart(CartItem cart) { CartItem item = CartItem( id: DateTime.now().toString(), + docId: cart.docId, prodId: cart.prodId, prodName: cart.prodName, prodPrice: cart.prodPrice, diff --git a/lib/utilities/build_cart.dart b/lib/utilities/build_cart.dart index c271ac2..1f2193c 100644 --- a/lib/utilities/build_cart.dart +++ b/lib/utilities/build_cart.dart @@ -1,13 +1,15 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import '../../../constants/colors.dart'; +import '../views/main/product/details.dart'; Dismissible buildCart( - void Function(String prodId) removeFromCart, - item, - BuildContext context, - void Function(String id) increaseQuantity, - void Function(String id) reduceQuantity, - ) { + void Function(String prodId) removeFromCart, + item, + BuildContext context, + void Function(String id) increaseQuantity, + void Function(String id) reduceQuantity, +) { return Dismissible( onDismissed: (direction) => removeFromCart(item.prodId), direction: DismissDirection.endToStart, @@ -69,61 +71,76 @@ Dismissible buildCart( key: ValueKey(item.id), child: Card( elevation: 3, - child: ListTile( - contentPadding: const EdgeInsets.only( - left: 10, - right: 10, - top: 5, - ), - leading: CircleAvatar( - backgroundColor: primaryColor, - backgroundImage: NetworkImage(item.prodImgUrl), - ), - title: Text( - item.prodName, - style: const TextStyle( - fontSize: 16, + child: GestureDetector( + onTap: () async{ + await FirebaseFirestore.instance + .collection('products') + .doc(item.docId) + .get().then((value) => + + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => DetailsScreen(product: value), + ), + ) + ); + }, + child: ListTile( + contentPadding: const EdgeInsets.only( + left: 10, + right: 10, + top: 5, ), - ), - subtitle: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text('\$${item.totalPrice}'), - const SizedBox(height: 5), - Row( - children: [ - GestureDetector( - onTap: () => increaseQuantity(item.id), - child: const Icon( - Icons.add, - color: primaryColor, + leading: CircleAvatar( + backgroundColor: primaryColor, + backgroundImage: NetworkImage(item.prodImgUrl), + ), + title: Text( + item.prodName, + style: const TextStyle( + fontSize: 16, + ), + ), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text('\$${item.totalPrice}'), + const SizedBox(height: 5), + Row( + children: [ + GestureDetector( + onTap: () => increaseQuantity(item.id), + child: const Icon( + Icons.add, + color: primaryColor, + ), ), - ), - const SizedBox(width: 10), - Text( - item.quantity.toString(), - style: const TextStyle( - fontWeight: FontWeight.bold, - fontSize: 18, + const SizedBox(width: 10), + Text( + item.quantity.toString(), + style: const TextStyle( + fontWeight: FontWeight.bold, + fontSize: 18, + ), ), - ), - const SizedBox(width: 10), - GestureDetector( - onTap: () => reduceQuantity(item.id), - child: const Icon( - Icons.remove, - color: primaryColor, + const SizedBox(width: 10), + GestureDetector( + onTap: () => reduceQuantity(item.id), + child: const Icon( + Icons.remove, + color: primaryColor, + ), ), - ), - ], + ], + ), + ], + ), + trailing: IconButton( + onPressed: () => removeFromCart(item.prodId), + icon: const Icon( + Icons.delete_forever, + color: primaryColor, ), - ], - ), - trailing: IconButton( - onPressed: () => removeFromCart(item.prodId), - icon: const Icon( - Icons.delete_forever, - color: primaryColor, ), ), ), diff --git a/lib/utilities/products_stream_builder.dart b/lib/utilities/products_stream_builder.dart index 5039937..816fc59 100644 --- a/lib/utilities/products_stream_builder.dart +++ b/lib/utilities/products_stream_builder.dart @@ -29,6 +29,7 @@ class ProductStreamBuilder extends StatelessWidget { // add to cart void addToCart( + var docId, var prodId, var prodName, var prodPrice, @@ -37,6 +38,7 @@ class ProductStreamBuilder extends StatelessWidget { cartData.addToCart( CartItem( id: '', + docId: docId, prodId: prodId, prodName: prodName, prodPrice: double.parse(prodPrice), @@ -185,6 +187,7 @@ class ProductStreamBuilder extends StatelessWidget { removeFromCart(data['prod_id']); } else { addToCart( + data.id, data['prod_id'], data['title'], data['price'], diff --git a/lib/views/main/customer/cart.dart b/lib/views/main/customer/cart.dart index ad9a118..97ed550 100644 --- a/lib/views/main/customer/cart.dart +++ b/lib/views/main/customer/cart.dart @@ -178,6 +178,7 @@ class _CartScreenState extends State { color: primaryColor, ), ), + showBadge: cartData.cartItems.isNotEmpty ? true:false, child: const Icon( Icons.shopping_bag_outlined, size: 30, diff --git a/lib/views/main/customer/customer_bottomNav.dart b/lib/views/main/customer/customer_bottomNav.dart index 82257fa..70be877 100644 --- a/lib/views/main/customer/customer_bottomNav.dart +++ b/lib/views/main/customer/customer_bottomNav.dart @@ -57,28 +57,30 @@ class _CustomerBottomNavState extends State { initialActiveIndex: currentPageIndex, style: TabStyle.reactCircle, items: [ - TabItem( + const TabItem( icon: Icons.house_siding, ), - TabItem( + const TabItem( icon: Icons.favorite_border, ), - TabItem( + const TabItem( icon: Icons.category_outlined, ), - TabItem( + const TabItem( icon: Icons.storefront, ), TabItem( icon: Consumer( builder: (context, data, child) => Badge( badgeContent: Text( - cartData.cartItemCount.toString(), - style: const TextStyle( - color: primaryColor, - ), - ), - child: Icon( + cartData.cartItemCount.toString(), + style: const TextStyle( + color: primaryColor, + ), + ) + , + showBadge: cartData.cartItems.isNotEmpty ? true:false, + child: Icon( Icons.shopping_bag_outlined, size: currentPageIndex == 4 ? 40 : 25, color: currentPageIndex == 4 ? primaryColor : Colors.white70, @@ -86,7 +88,7 @@ class _CustomerBottomNavState extends State { ), ), ), - TabItem( + const TabItem( icon: Icons.person_outline, ) ], diff --git a/lib/views/main/customer/order.dart b/lib/views/main/customer/order.dart index b6ea3f1..f0a7c48 100644 --- a/lib/views/main/customer/order.dart +++ b/lib/views/main/customer/order.dart @@ -1,3 +1,4 @@ +import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import '../../../constants/colors.dart'; @@ -23,7 +24,6 @@ class CustomerOrderScreen extends StatelessWidget { orderData.removeFromOrder(id); } - // pay through stripe void payNow() async { // TODO: Implement Pay now @@ -231,12 +231,19 @@ class CustomerOrderScreen extends StatelessWidget { ), subtitle: Text('\$${subData.totalPrice}'), trailing: IconButton( - onPressed: () => Navigator.of(context).push( - MaterialPageRoute( - builder: (context) => - DetailsScreen(product: subData), - ), - ), + onPressed: () async { + await FirebaseFirestore.instance + .collection('products') + .doc(subData.docId) + .get() + .then((value) => + Navigator.of(context).push( + MaterialPageRoute( + builder: (context) => + DetailsScreen(product: value), + ), + )); + }, icon: const Icon( Icons.chevron_right, color: primaryColor, diff --git a/lib/views/main/product/details.dart b/lib/views/main/product/details.dart index b43b284..646e10f 100644 --- a/lib/views/main/product/details.dart +++ b/lib/views/main/product/details.dart @@ -144,7 +144,8 @@ class _DetailsScreenState extends State cartData.addToCart( CartItem( id: '', - prodId: product.prod_id, + docId: product.id, + prodId: product['prod_id'], prodName: product['title'], prodPrice: double.parse(product['price']), prodImgUrl: product['images'][0], diff --git a/cart_2.png b/screenshots/New folder/cart_2.png similarity index 100% rename from cart_2.png rename to screenshots/New folder/cart_2.png diff --git a/screenshots/New folder/cart_number.png b/screenshots/New folder/cart_number.png new file mode 100644 index 0000000..245d747 Binary files /dev/null and b/screenshots/New folder/cart_number.png differ diff --git a/screenshots/New folder/cart_checkout.png b/screenshots/cart_checkout.png similarity index 100% rename from screenshots/New folder/cart_checkout.png rename to screenshots/cart_checkout.png diff --git a/screenshots/New folder/cart_remove.png b/screenshots/cart_remove.png similarity index 100% rename from screenshots/New folder/cart_remove.png rename to screenshots/cart_remove.png diff --git a/screenshots/New folder/clear_cart.png b/screenshots/clear_cart.png similarity index 100% rename from screenshots/New folder/clear_cart.png rename to screenshots/clear_cart.png diff --git a/screenshots/New folder/order.png b/screenshots/order.png similarity index 100% rename from screenshots/New folder/order.png rename to screenshots/order.png diff --git a/screenshots/New folder/order_1.png b/screenshots/order_1.png similarity index 100% rename from screenshots/New folder/order_1.png rename to screenshots/order_1.png diff --git a/screenshots/New folder/order_2.png b/screenshots/order_2.png similarity index 100% rename from screenshots/New folder/order_2.png rename to screenshots/order_2.png diff --git a/screenshots/New folder/order_del.png b/screenshots/order_del.png similarity index 100% rename from screenshots/New folder/order_del.png rename to screenshots/order_del.png diff --git a/screenshots/New folder/pay_now.png b/screenshots/pay_now.png similarity index 100% rename from screenshots/New folder/pay_now.png rename to screenshots/pay_now.png