From e1d96ee34e088501b3cd296066fba6fe2cf39a47 Mon Sep 17 00:00:00 2001 From: saritabirare Date: Fri, 6 Sep 2024 17:55:52 +0530 Subject: [PATCH] new changes --- lib/screens/order/checkout_screen.dart | 28 ++++-- .../order/order_confermation_screen.dart | 46 ++++++--- lib/screens/product/cart_screen.dart | 60 ++++++++---- lib/widgets/product_card.dart | 96 +++++++++++-------- pubspec.lock | 8 ++ pubspec.yaml | 1 + 6 files changed, 162 insertions(+), 77 deletions(-) diff --git a/lib/screens/order/checkout_screen.dart b/lib/screens/order/checkout_screen.dart index a7c1fa0..6e8999a 100644 --- a/lib/screens/order/checkout_screen.dart +++ b/lib/screens/order/checkout_screen.dart @@ -368,15 +368,31 @@ class _CheckoutScreenState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - 'Subtotal: \₹${_cartController.subtotal.value.toStringAsFixed(2)}'), - Text( - 'GST: \₹${_cartController.gstTotal.value.toStringAsFixed(2)}'), - Text( - 'Grand Total: \₹${_cartController.grandTotal.value.toStringAsFixed(2)}'), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Subtotal:'), + Text('₹${_cartController.subtotal.value.toStringAsFixed(2)}'), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('GST:'), + Text('₹${_cartController.gstTotal.value.toStringAsFixed(2)}'), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Grand Total:'), + Text('₹${_cartController.grandTotal.value.toStringAsFixed(2)}'), + ], + ), ], ), ), + ], ), ), diff --git a/lib/screens/order/order_confermation_screen.dart b/lib/screens/order/order_confermation_screen.dart index bce749a..71bdc3e 100644 --- a/lib/screens/order/order_confermation_screen.dart +++ b/lib/screens/order/order_confermation_screen.dart @@ -155,17 +155,33 @@ class _OrderConfermationScreenState extends State { Padding( padding: EdgeInsets.all(Get.width * 0.02), child: Column( - mainAxisAlignment: MainAxisAlignment.end, + crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( - 'Subtotal: \₹${_cartController.subtotal.value.toStringAsFixed(2)}'), - Text( - 'GST: \₹${_cartController.gstTotal.value.toStringAsFixed(2)}'), - Text( - 'Grand Total: \₹${_cartController.grandTotal.value.toStringAsFixed(2)}'), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Subtotal:'), + Text('₹${_cartController.subtotal.value.toStringAsFixed(2)}'), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('GST:'), + Text('₹${_cartController.gstTotal.value.toStringAsFixed(2)}'), + ], + ), + Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text('Grand Total:'), + Text('₹${_cartController.grandTotal.value.toStringAsFixed(2)}'), + ], + ), ], ), ), + ], ), ), @@ -189,11 +205,17 @@ class _OrderConfermationScreenState extends State { children: [ Padding( padding: const EdgeInsets.all(8.0), - child: Text( - "Address :${widget.placedOrder!.shipTo}", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, + child: TextField( + controller: TextEditingController( + text: widget.placedOrder!.shipTo, + ), + decoration: InputDecoration( + hintText: "Address : ${widget.placedOrder!.shipTo}", + hintStyle: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.w400, + ), + border: OutlineInputBorder(), ), ), ), diff --git a/lib/screens/product/cart_screen.dart b/lib/screens/product/cart_screen.dart index 2001d60..89a922a 100644 --- a/lib/screens/product/cart_screen.dart +++ b/lib/screens/product/cart_screen.dart @@ -110,13 +110,19 @@ class _CartScreenState extends State { height: 10, ), Obx(() { - return Text( - "Subtotal Price: ₹ ${_cartController.subtotal.value}", - style: GoogleFonts.roboto( - fontSize: 15, - fontWeight: FontWeight.w700, - color: Colors.white, - ), + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Subtotal Price: ", + style: GoogleFonts.roboto( + fontSize: 15, + + color: Colors.black, + ), + ), + Text("₹ ${_cartController.subtotal.value}"), + ], ); }), @@ -126,24 +132,36 @@ class _CartScreenState extends State { // height: 16, // ), Obx(() { - return Text( - "gstTotal Price: ₹ ${_cartController.gstTotal.value}", - style: GoogleFonts.roboto( - fontSize: 15, - fontWeight: FontWeight.w700, - color: Colors.white, - ), + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "gstTotal Price: ", + style: GoogleFonts.roboto( + fontSize: 15, + + color: Colors.black, + ), + ), + Text("₹ ${_cartController.gstTotal.value}"), + ], ); }), Obx(() { - return Text( - "grandTotal Price: ₹ ${_cartController.grandTotal.value}", - style: GoogleFonts.roboto( - fontSize: 15, - fontWeight: FontWeight.w700, - color: Colors.white, - ), + return Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "grandTotal Price:", + style: GoogleFonts.roboto( + fontSize: 15, + + color: Colors.black, + ), + ), + Text(" ₹ ${_cartController.grandTotal.value}"), + ], ); }), diff --git a/lib/widgets/product_card.dart b/lib/widgets/product_card.dart index 026e00e..89a9458 100644 --- a/lib/widgets/product_card.dart +++ b/lib/widgets/product_card.dart @@ -7,7 +7,7 @@ import 'package:get/get.dart'; import 'package:google_fonts/google_fonts.dart'; import '../models/product_model1.dart'; -import '../screens/product/cart_screen.dart'; + import '../utils/show_snackbar.dart'; class ProductCard extends StatefulWidget { @@ -42,6 +42,11 @@ class _ProductCardState extends State { final CartController _cartController = Get.put(CartController()); bool showQuantity = widget.isInCart || widget.isCheckout || widget.isConfirmation; bool isProductInCart = _cartController.cartList.contains(widget.productModel); + + + int currentQuantity = isProductInCart + ? _cartController.cartList.firstWhere((p) => p.id == widget.productModel!.id).quantity + : widget.productModel!.quantity; return GestureDetector( onTap: () => widget.isInCart || widget.isCheckout ? null @@ -96,7 +101,7 @@ class _ProductCardState extends State { ), showQuantity ? Text( - "Quantity: ${widget.productModel!.quantity.toString()}", + "Quantity: ${currentQuantity}", style: GoogleFonts.roboto( fontSize: 15, fontWeight: FontWeight.w700, @@ -120,6 +125,45 @@ class _ProductCardState extends State { mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ + SizedBox( + height: 24, + width: 24, + child: ElevatedButton( + onPressed: () { + _cartController.decreaseQuantity(widget.productModel!); + setState(() { + // Update the local quantity to reflect the change + currentQuantity = _cartController + .cartList + .firstWhere((p) => + p.id == + widget.productModel!.id) + .quantity; + }); + }, + style: ElevatedButton.styleFrom( + padding: EdgeInsets.zero, + shape: RoundedRectangleBorder( + borderRadius: + BorderRadius.circular(8.0), + ), + ), + child: Text( + '-', + style: GoogleFonts.roboto( + fontSize: 16, + fontWeight: FontWeight.w800, + ), + ), + ), + ), + Text( + "${currentQuantity}", + style: const TextStyle( + color: Colors.white, + fontSize: 16, + ), + ), SizedBox( height: 24, width: 24, @@ -127,8 +171,13 @@ class _ProductCardState extends State { onPressed: () { _cartController.increaseQuantity(widget.productModel!); setState(() { - widget.quantity = widget.productModel!.quantity; - + // Update the local quantity to reflect the change + currentQuantity = _cartController + .cartList + .firstWhere((p) => + p.id == + widget.productModel!.id) + .quantity; }); }, style: ElevatedButton.styleFrom( @@ -147,40 +196,6 @@ class _ProductCardState extends State { ), ), ), - Text( - "${widget.quantity}", - style: const TextStyle( - color: Colors.white, - fontSize: 16, - ), - ), - SizedBox( - height: 24, - width: 24, - child: ElevatedButton( - onPressed: () { - _cartController.decreaseQuantity(widget.productModel!); - setState(() { - widget.quantity = widget.productModel!.quantity; - }); - - }, - style: ElevatedButton.styleFrom( - padding: EdgeInsets.zero, - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(8.0), - ), - ), - child: Text( - '-', - style: GoogleFonts.roboto( - fontSize: 16, - fontWeight: FontWeight.w800, - ), - ), - ), - ), ], ), ), @@ -188,6 +203,11 @@ class _ProductCardState extends State { IconButton( onPressed: () { _cartController.removeFromCart(widget.productModel!); + showSnackbar("Product removed successfully!"); + setState(() { + // Update the local quantity + currentQuantity = 1; + }); }, icon: const Icon( Icons.delete_outline_rounded, diff --git a/pubspec.lock b/pubspec.lock index 398fb94..3c7209e 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -144,6 +144,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.6.6" + get_storage: + dependency: "direct main" + description: + name: get_storage + sha256: "39db1fffe779d0c22b3a744376e86febe4ade43bf65e06eab5af707dc84185a2" + url: "https://pub.dev" + source: hosted + version: "2.1.1" google_fonts: dependency: "direct main" description: diff --git a/pubspec.yaml b/pubspec.yaml index 8f22a41..2f48db9 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: http: ^1.2.2 shared_preferences: ^2.2.3 logger: ^2.4.0 + get_storage: ^2.1.1 dev_dependencies: flutter_test: