From 174d7afa99994929b1002a143e0d25337f023b2f Mon Sep 17 00:00:00 2001 From: saritabirare Date: Wed, 11 Sep 2024 12:24:48 +0530 Subject: [PATCH] 1)get all Place Order api integration done 2) single Place order api integration done 3) Refresh inidicator added 4)Caps Functionality added --- .../get_order_placed_controller.dart | 67 +- lib/controller/get_place_order_service.dart | 131 +++- .../get_single_placed_order_service.dart | 30 + lib/controller/place_order_service.dart | 6 +- lib/models/oder_place_model.dart | 42 -- lib/models/order_item_model.dart | 181 ++---- lib/models/place_order_list_model.dart | 136 ++++ lib/screens/order/checkout_screen.dart | 53 +- .../order/order_confermation_screen.dart | 54 +- .../order_fullfilment_screen.dart | 8 +- .../order_management_detail_screen.dart | 282 +++++--- .../order_management_screen.dart | 603 +++++++++++++----- lib/screens/product/cart_screen.dart | 16 +- .../product/product_catalog_screen.dart | 10 +- .../product/product_detail_screen.dart | 87 ++- lib/utils/constants.dart | 4 +- lib/widgets/product_card.dart | 67 +- pubspec.lock | 8 + pubspec.yaml | 1 + 19 files changed, 1183 insertions(+), 603 deletions(-) create mode 100644 lib/controller/get_single_placed_order_service.dart create mode 100644 lib/models/place_order_list_model.dart diff --git a/lib/controller/get_order_placed_controller.dart b/lib/controller/get_order_placed_controller.dart index af5c9ac..bed7dbc 100644 --- a/lib/controller/get_order_placed_controller.dart +++ b/lib/controller/get_order_placed_controller.dart @@ -1,40 +1,63 @@ -import 'package:cheminova/controller/get_place_order_service.dart'; -import 'package:cheminova/controller/product_service.dart'; -import 'package:cheminova/models/oder_place_model.dart'; -import 'package:cheminova/models/product_model1.dart'; +import 'package:cheminova/controller/get_single_placed_order_service.dart'; +import 'package:cheminova/controller/place_order_controller.dart'; +import 'package:cheminova/models/place_order_list_model.dart'; import 'package:get/get.dart'; +import '../models/oder_place_model.dart'; +import '../models/product_model1.dart'; +import '../utils/log_service.dart'; +import 'get_place_order_service.dart'; class GetPlacedOrderController extends GetxController { - final GetOrderPlacedServcie _getOrderPlacedServcie = GetOrderPlacedServcie(); - var products = [].obs; + final GetOrderPlacedService _getOrderPlacedService = GetOrderPlacedService(); + final OrderPlacedController _orderPlacedController = Get.put(OrderPlacedController()); + final GetSingleOrderPlacedService _getSingleOrderPlacedService = GetSingleOrderPlacedService(); + var placedOrders = [].obs; + var products = [].obs; - int _currentPage = 1; - bool isLoading = false; + var isLoading = false.obs; @override void onInit() { super.onInit(); - + getOrders(); // Fetch the orders immediately on initialization } - Future getOrder(String id) async { - if (isLoading) return; - isLoading = true; + Future getOrders() async { + + final fetchedOrders = await _getOrderPlacedService.getPlacedOrders(); + + if (fetchedOrders != null && fetchedOrders.isNotEmpty) { + placedOrders.addAll(fetchedOrders); + //logger.w("Fetched orders: $fetchedOrders"); + + } else { + //logger.w("No orders fetched"); + } + } + + + Future searchOrder() async { try { - - final fetchedProducts = await _getOrderPlacedServcie.getPlacedOrder(); - - - if (fetchedProducts != null) { - - products.addAll(fetchedProducts); + isLoading.value = true; + final order = await _getSingleOrderPlacedService.getSinglePlacedOrder(placedOrders[0].id); + if (order != null) { + placedOrders.clear(); // Clear existing orders if needed + placedOrders.add(order); + } else { + // Handle order not found case } } catch (e) { - print("Error fetching products: $e"); + // Handle exceptions } finally { - isLoading = false; - update(); + isLoading.value = false; } } + + // Optional: Reset the pagination if needed + void resetPagination() { + _getOrderPlacedService.resetPagination(); + placedOrders.clear(); // Clear existing data + getOrders(); // Fetch fresh data + } } diff --git a/lib/controller/get_place_order_service.dart b/lib/controller/get_place_order_service.dart index 932317b..5c10096 100644 --- a/lib/controller/get_place_order_service.dart +++ b/lib/controller/get_place_order_service.dart @@ -1,35 +1,122 @@ -import 'package:cheminova/models/oder_place_model.dart'; - +import 'package:cheminova/models/place_order_list_model.dart'; +import '../models/oder_place_model.dart'; import '../utils/common_api_service.dart'; import '../utils/show_snackbar.dart'; -class GetOrderPlacedServcie{ - Future?> getPlacedOrder() async { +class GetOrderPlacedService { + int _currentPage = 1; // Initialize with the first page + //int _limit = 100; // Start with a fixed limit, can be adjusted + final List _allOrders = []; // To store all fetched orders + bool _hasMoreOrders = true; // To check if there are more orders to fetch + + Future?> getPlacedOrders() async { try { - String url; + while (_hasMoreOrders) { + // Construct the API URL with pagination parameters + String url = "/api/get-placed-order-pd?page=$_currentPage"; - url = "/api/get-placed-order-pd?id=66cc7869f02b935094127a27"; + final response = await commonApiService>( + method: "GET", + url: url, + fromJson: (json) { + if (json['plcaedOrders'] != null) { + final List orders = (json['plcaedOrders'] as List) + .map((orderJson) => PlacedOrderList.fromJson(orderJson as Map)) + .toList(); - final response = await commonApiService>( - method: "GET", - url: url, - fromJson: (json) { - if (json['plcaedOrders'] != null) { - final List products = (json['plcaedOrders'] as List) - .map((productJson) => PlacedOrderModel.fromJson(productJson as Map)) - .toList(); - return products; - } else { - return []; - } - }, - ); - return response; + if (orders.isNotEmpty) { + _allOrders.addAll(orders); + _currentPage++; + // _limit += orders.length; // Adjust limit based on the number of fetched orders + } else { + _hasMoreOrders = false; // Stop fetching if no more orders are returned + } + + return orders; + } else { + _hasMoreOrders = false; // Stop if there are no orders at all + return []; + } + }, + ); + + if (response == null || response.isEmpty) { + _hasMoreOrders = false; // Stop fetching if the response is empty + } + } + + return _allOrders; } catch (e) { showSnackbar(e.toString()); - return null; } } + + // Optional: Reset the pagination and orders when needed + void resetPagination() { + _currentPage = 1; + //_limit = 100; // Reset the limit to the initial value + _allOrders.clear(); // Clear the list of orders + _hasMoreOrders = true; // Reset the flag to allow fetching again + } + + + + + + } + + +// +// import 'package:cheminova/models/place_order_list_model.dart'; +// +// import '../models/oder_place_model.dart'; +// import '../utils/common_api_service.dart'; +// import '../utils/show_snackbar.dart'; +// +// class GetOrderPlacedService { +// int _currentPage = 1; // Initialize with the first page +// int _limit = 10; // Fixed limit, you can change this as needed +// final List _allOrders = []; +// int? totalOrders ; +// Future?> getPlacedOrders() async { +// try { +// // Construct the API URL with pagination parameters +// String url = "/api/get-placed-order-pd?page=$_currentPage&limit=$_limit"; +// +// final response = await commonApiService>( +// method: "GET", +// url: url, +// fromJson: (json) { +// if (json['plcaedOrders'] != null) { +// final List orders = (json['plcaedOrders'] as List) +// .map((orderJson) => PlacedOrderList.fromJson(orderJson as Map)) +// .toList(); +// // Automatically increase the page number for the next request +// if (orders.isNotEmpty) { +// _currentPage++; +// _limit+= orders.length; +// +// } +// return orders; +// } else { +// return []; +// } +// }, +// ); +// +// return response; +// } catch (e) { +// showSnackbar(e.toString()); +// return null; +// } +// } +// +// // Optional: Reset the pagination when needed +// void resetPagination() { +// _currentPage = 1; +// _limit = 100; +// } +// } diff --git a/lib/controller/get_single_placed_order_service.dart b/lib/controller/get_single_placed_order_service.dart new file mode 100644 index 0000000..7f67814 --- /dev/null +++ b/lib/controller/get_single_placed_order_service.dart @@ -0,0 +1,30 @@ +import 'package:cheminova/models/place_order_list_model.dart'; // Import your model +import '../utils/common_api_service.dart'; +import '../utils/show_snackbar.dart'; + +class GetSingleOrderPlacedService { + Future getSinglePlacedOrder(String orderId) async { + try { + // Construct the API URL for the single placed order + String url = "/api/get-single-placed-order-pd/$orderId"; + + final response = await commonApiService( + method: "GET", + url: url, + fromJson: (json) { + if (json['singleOrder'] != null) { + // Convert the JSON response to a PlacedOrderList model + return PlacedOrderList.fromJson(json['singleOrder'] as Map); + } else { + throw Exception("Order not found"); // Throw an exception if not found + } + }, + ); + + return response; + } catch (e) { + showSnackbar(e.toString()); + return null; + } + } +} diff --git a/lib/controller/place_order_service.dart b/lib/controller/place_order_service.dart index 418bade..79141cb 100644 --- a/lib/controller/place_order_service.dart +++ b/lib/controller/place_order_service.dart @@ -12,9 +12,9 @@ class OrderPlacedService { Future placeOrder(PlacedOrderModel orderDetails, String token) async { //try { - logger.w("orderjson ${jsonEncode(orderDetails.toJson())}"); + // logger.w("orderjson ${jsonEncode(orderDetails.toJson())}"); final response = await dio.post( - 'https://cheminova-api-2.onrender.com/api/order-place', // Ensure this is your correct endpoint + 'https://api.cnapp.co.in/api/order-place', // Ensure this is your correct endpoint data: jsonEncode(orderDetails.toJson()), options: Options( headers: { @@ -23,7 +23,7 @@ class OrderPlacedService { }, ), ); - logger.w("Status code,${response.statusCode}"); + //logger.w("Status code,${response.statusCode}"); if (response.statusCode != 201) { throw Exception('Failed to place order'); diff --git a/lib/models/oder_place_model.dart b/lib/models/oder_place_model.dart index 112108f..d5ea5c1 100644 --- a/lib/models/oder_place_model.dart +++ b/lib/models/oder_place_model.dart @@ -139,45 +139,3 @@ class OrderItem { } } - - - -// class Brand { -// String id; -// String brandName; -// -// Brand({ -// required this.id, -// required this.brandName, -// }); -// -// factory Brand.fromJson(Map json) => Brand( -// id: json["_id"], -// brandName: json["brandName"], -// ); -// -// Map toJson() => { -// "_id": id, -// "brandName": brandName, -// }; -// } -// -// class Category { -// String id; -// String categoryName; -// -// Category({ -// required this.id, -// required this.categoryName, -// }); -// -// factory Category.fromJson(Map json) => Category( -// id: json["_id"], -// categoryName: json["categoryName"], -// ); -// -// Map toJson() => { -// "_id": id, -// "categoryName": categoryName, -// }; -// } diff --git a/lib/models/order_item_model.dart b/lib/models/order_item_model.dart index 70a198a..1516f1e 100644 --- a/lib/models/order_item_model.dart +++ b/lib/models/order_item_model.dart @@ -1,130 +1,51 @@ -// import 'brand_model.dart'; -// import 'category_model.dart'; -// -// class OrderItem { -// final String id; -// final String sku; -// final String name; -// final Category category; -// final Brand brand; -// final double price; -// final double gst; -// final int hsnCode; -// final String description; -// final String productStatus; -// final String addedBy; -// final List image; -// final DateTime createdAt; -// final DateTime updatedAt; -// final int count; -// -// OrderItem({ -// required this.id, -// required this.sku, -// required this.name, -// required this.category, -// required this.brand, -// required this.price, -// required this.gst, -// required this.hsnCode, -// required this.description, -// required this.productStatus, -// required this.addedBy, -// required this.image, -// required this.createdAt, -// required this.updatedAt, -// required this.count, -// }); -// -// factory OrderItem.fromJson(Map json) { -// return OrderItem( -// id: json['_id'], -// sku: json['SKU'], -// name: json['name'], -// category: Category.fromJson(json['category']), -// brand: Brand.fromJson(json['brand']), -// price: json['price'].toDouble(), -// gst: json['GST'].toDouble(), -// hsnCode: json['HSN_Code'], -// description: json['description'], -// productStatus: json['product_Status'], -// addedBy: json['addedBy'], -// image: List.from(json['image'] ?? []), -// createdAt: DateTime.parse(json['createdAt']), -// updatedAt: DateTime.parse(json['updatedAt']), -// count: json['count'], -// ); -// } -// -// Map toJson() { -// return { -// '_id': id, -// 'SKU': sku, -// 'name': name, -// 'category': category, -// 'brand': brand, -// 'price': price, -// 'GST': gst, -// 'HSN_Code': hsnCode, -// 'description': description, -// 'product_Status': productStatus, -// 'addedBy': addedBy, -// 'image': image, -// 'createdAt': createdAt.toIso8601String(), -// 'updatedAt': updatedAt.toIso8601String(), -// 'count': count, -// }; -// } -// } -// -// // -// class Category { -// final String id; -// final String categoryName; -// -// Category({ -// required this.id, -// required this.categoryName, -// }); -// -// factory Category.fromJson(Map json) { -// return Category( -// id: json['_id'], -// categoryName: json['categoryName'], -// ); -// } -// } -// -// class Brand { -// final String id; -// final String brandName; -// -// Brand({ -// required this.id, -// required this.brandName, -// }); -// -// factory Brand.fromJson(Map json) { -// return Brand( -// id: json['_id'], -// brandName: json['brandName'], -// ); -// } -// } -// // -// // class AddedBy { -// // final String id; -// // final String name; -// // -// // AddedBy({ -// // required this.id, -// // required this.name, -// // }); -// // -// // factory AddedBy.fromJson(Map json) { -// // return AddedBy( -// // id: json['_id'], -// // name: json['name'], -// // ); -// // } -// // } +class PlaceOrderItem1 { + final String sku; + String? id; + List? image; + final String name; + final String categoryName; + final String brandName; + final double price; + final int quantity; + + PlaceOrderItem1({ + required this.sku, + this.id, + this.image, + required this.name, + required this.categoryName, + required this.brandName, + required this.price, + required this.quantity, + }); + + factory PlaceOrderItem1.fromJson(Map json) { + return PlaceOrderItem1( + id: json['id'], + sku: json['SKU'], + name: json['name'], + categoryName: json['categoryName'], + brandName: json['brandName'], + price: json['price'].toDouble(), + quantity: json['quantity'], image: null, + ); + } + + Map toJson() { + return { + 'SKU': sku, + 'name': name, + 'categoryName': categoryName, + 'brandName': brandName, + 'price': price, + 'quantity': quantity, + }; + } + + @override + String toString() { + return 'OrderItem(sku: $sku, name: $name, categoryName: $categoryName, ' + 'brandName: $brandName, price: $price, quantity: $quantity)'; + } +} + diff --git a/lib/models/place_order_list_model.dart b/lib/models/place_order_list_model.dart new file mode 100644 index 0000000..558900d --- /dev/null +++ b/lib/models/place_order_list_model.dart @@ -0,0 +1,136 @@ +class PlacedOrderList { + final String id; + final String paymentMode; + final String shipTo; + final String billTo; + final List orderItem; + final double subtotal; + final double gstTotal; + final double grandTotal; + final String status; + final String addedBy; + final bool isCancelled; + final bool isDelivered; + final String deliveredDate; + final String uniqueId; + final DateTime createdAt; + final DateTime updatedAt; + + PlacedOrderList({ + required this.id, + required this.paymentMode, + required this.shipTo, + required this.billTo, + required this.orderItem, + required this.subtotal, + required this.gstTotal, + required this.grandTotal, + required this.status, + required this.addedBy, + required this.isCancelled, + required this.isDelivered, + required this.deliveredDate, + required this.uniqueId, + required this.createdAt, + required this.updatedAt, + }); + + factory PlacedOrderList.fromJson(Map json) { + return PlacedOrderList( + id: json['_id'], + paymentMode: json['paymentMode'], + shipTo: json['shipTo'], + billTo: json['billTo'], + orderItem: (json['orderItem'] as List) + .map((item) => OrderItem1.fromJson(item)) + .toList(), + subtotal: json['subtotal'].toDouble(), + gstTotal: json['gstTotal'].toDouble(), + grandTotal: json['grandTotal'].toDouble(), + status: json['status'], + addedBy: json['addedBy'], + isCancelled: json['iscancelled'], + isDelivered: json['isDelivered'], + deliveredDate: json['DeliveredDate'], + uniqueId: json['uniqueId'], + createdAt: DateTime.parse(json['createdAt']), + updatedAt: DateTime.parse(json['updatedAt']), + ); + } + + Map toJson() { + return { + '_id': id, + 'paymentMode': paymentMode, + 'shipTo': shipTo, + 'billTo': billTo, + 'orderItem': orderItem.map((item) => item.toJson()).toList(), + 'subtotal': subtotal, + 'gstTotal': gstTotal, + 'grandTotal': grandTotal, + 'status': status, + 'addedBy': addedBy, + 'iscancelled': isCancelled, + 'isDelivered': isDelivered, + 'DeliveredDate': deliveredDate, + 'uniqueId': uniqueId, + 'createdAt': createdAt.toIso8601String(), + 'updatedAt': updatedAt.toIso8601String(), + }; + } + + @override + String toString() { + return 'PlacedOrderList(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, ' + 'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, ' + 'status: $status, addedBy: $addedBy, isCancelled: $isCancelled, isDelivered: $isDelivered, ' + 'deliveredDate: $deliveredDate, uniqueId: $uniqueId, createdAt: $createdAt, updatedAt: $updatedAt)'; + } +} + +class OrderItem1 { + final String sku; + final String name; + final String categoryName; + final String brandName; + final double price; + final int quantity; + + OrderItem1({ + required this.sku, + required this.name, + required this.categoryName, + required this.brandName, + required this.price, + required this.quantity, + }); + + factory OrderItem1.fromJson(Map json) { + return OrderItem1( + sku: json['SKU'], + name: json['name'], + categoryName: json['categoryName'], + brandName: json['brandName'], + price: json['price'].toDouble(), + quantity: json['quantity'], + ); + } + + Map toJson() { + return { + 'SKU': sku, + 'name': name, + 'categoryName': categoryName, + 'brandName': brandName, + 'price': price, + 'quantity': quantity, + }; + } + + @override + String toString() { + return 'OrderItem(sku: $sku, name: $name, categoryName: $categoryName, ' + 'brandName: $brandName, price: $price, quantity: $quantity)'; + } +} + diff --git a/lib/screens/order/checkout_screen.dart b/lib/screens/order/checkout_screen.dart index 6e8999a..e22c0dc 100644 --- a/lib/screens/order/checkout_screen.dart +++ b/lib/screens/order/checkout_screen.dart @@ -24,9 +24,9 @@ import 'order_confermation_screen.dart'; class CheckoutScreen extends StatefulWidget { final Product? productModel; - PlacedOrderModel? placeOrder; - - CheckoutScreen({super.key, this.productModel, this.placeOrder}); + PlacedOrderModel? placeOrder; + List? selectedProducts; + CheckoutScreen({super.key, this.productModel, this.placeOrder,this.selectedProducts}); @override State createState() => _CheckoutScreenState(); @@ -37,7 +37,7 @@ class _CheckoutScreenState extends State { final ProductService _productService = ProductService(); final ProductController _productController = Get.put(ProductController()); final OrderPlacedController _orderPlacedController = - Get.put(OrderPlacedController()); + Get.put(OrderPlacedController()); final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); int currentPage = 1; @@ -55,7 +55,7 @@ class _CheckoutScreenState extends State { @override void initState() { super.initState(); - // _getOrder(); + // _getOrder(); _loadSelectedAddress(); _loadSelectedPaymentMode(); @@ -137,8 +137,8 @@ class _CheckoutScreenState extends State { count: product.quantity, //category:product.category, category:Category(id: product.category.id, categoryName: product.category.categoryName), - // brand:product.brand, - brand:Brand(id: product.brand.id, brandName: product.brand.brandName), + // brand:product.brand, + brand:Brand(id: product.brand.id, brandName: product.brand.brandName), v: 0, addedBy: product.addedBy, ); }).toList(); @@ -157,7 +157,7 @@ class _CheckoutScreenState extends State { await _orderPlacedController.placeOrder(); if (_orderPlacedController.isLoading.value) { - showSnackbar("OderPlaced Successfully"); + showSnackbar("Order Placed Successfully"); Get.to(() => OrderConfermationScreen( placedOrder: _orderPlacedController.placedOrder1.value, )); @@ -165,7 +165,7 @@ class _CheckoutScreenState extends State { } catch (e) { print("PlaceOrderScreen error: $e"); } - } + } @@ -292,7 +292,7 @@ class _CheckoutScreenState extends State { SizedBox( height: Get.height * 0.035, child: RadioListTile( - title: const Text("cheque"), + title: const Text("Cheque"), contentPadding: EdgeInsets.zero, value: "cheque", groupValue: _groupValue, @@ -302,7 +302,7 @@ class _CheckoutScreenState extends State { SizedBox( height: Get.height * 0.035, child: RadioListTile( - title: const Text("online-transfer"), + title: const Text("Online transfer"), contentPadding: EdgeInsets.zero, value: "online-transfer", groupValue: _groupValue, @@ -311,7 +311,7 @@ class _CheckoutScreenState extends State { ), SizedBox( child: RadioListTile( - title: const Text("credit"), + title: const Text("Credit"), contentPadding: EdgeInsets.zero, value: "credit", groupValue: _groupValue, @@ -345,20 +345,20 @@ class _CheckoutScreenState extends State { itemCount: _cartController.cartList.length, itemBuilder: (context, index) { final cartItem = - _cartController.cartList[index]; + _cartController.cartList[index]; return ProductCard( productModel:_cartController.cartList[index] , isCheckout: true, - quantity: _cartController.cartList[0].quantity, + quantity: _cartController.cartList[0].quantity, - // ListTile( - // title: Text(cartItem.name ?? 'N/A'), - // subtitle: Text( - // 'Quantity: ${cartItem.quantity}'), - // trailing: Text( - // 'Price: \₹${cartItem.price.toStringAsFixed(2)}'), - // ); + // ListTile( + // title: Text(cartItem.name ?? 'N/A'), + // subtitle: Text( + // 'Quantity: ${cartItem.quantity}'), + // trailing: Text( + // 'Price: \₹${cartItem.price.toStringAsFixed(2)}'), + // ); );}, ), ), @@ -369,30 +369,29 @@ class _CheckoutScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( - mainAxisAlignment: MainAxisAlignment.spaceBetween, + mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Subtotal:'), + Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)), Text('₹${_cartController.subtotal.value.toStringAsFixed(2)}'), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('GST:'), + Text('GST',style: TextStyle(fontWeight: FontWeight.bold)), Text('₹${_cartController.gstTotal.value.toStringAsFixed(2)}'), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Grand Total:'), + Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)), Text('₹${_cartController.grandTotal.value.toStringAsFixed(2)}'), ], ), ], ), ), - ], ), ), @@ -428,4 +427,4 @@ class _CheckoutScreenState extends State { ), ); } -} +} \ No newline at end of file diff --git a/lib/screens/order/order_confermation_screen.dart b/lib/screens/order/order_confermation_screen.dart index 71bdc3e..589799c 100644 --- a/lib/screens/order/order_confermation_screen.dart +++ b/lib/screens/order/order_confermation_screen.dart @@ -38,11 +38,11 @@ class _OrderConfermationScreenState extends State { // ), // ]; - void _getOrder(){ - final details = _getPlacedOrderController.getOrder(_cartController.cartList[0].id); - showSnackbar("Get Placed Order Sucessfully"); - print("dffgfg,$details"); - } + // void _getOrder(){ + // final details = _getPlacedOrderController.getOrder(); + // showSnackbar("Get Placed Order Sucessfully"); + // print("dffgfg,$details"); + // } @override Widget build(BuildContext context) { final orderItems = _placedController.placedOrder1; @@ -128,7 +128,7 @@ class _OrderConfermationScreenState extends State { 'Order Summary', style: GoogleFonts.roboto( fontSize: Get.width * 0.04, - fontWeight: FontWeight.w500, + fontWeight: FontWeight.bold, color: Colors.black, ), ), @@ -160,21 +160,21 @@ class _OrderConfermationScreenState extends State { Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Subtotal:'), + Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)), Text('₹${_cartController.subtotal.value.toStringAsFixed(2)}'), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('GST:'), + Text('GST',style: TextStyle(fontWeight: FontWeight.bold)), Text('₹${_cartController.gstTotal.value.toStringAsFixed(2)}'), ], ), Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text('Grand Total:'), + Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)), Text('₹${_cartController.grandTotal.value.toStringAsFixed(2)}'), ], ), @@ -219,18 +219,8 @@ class _OrderConfermationScreenState extends State { ), ), ), - // Padding( - // padding: const EdgeInsets.all(8.0), - // child: Text( - // "Contact: +91 9123456789", - // style: GoogleFonts.roboto( - // fontSize: Get.width * 0.04, - // fontWeight: FontWeight.w400, - // ), - // ), - // ), - ], - ), + + ]), ), ), Card( @@ -240,7 +230,7 @@ class _OrderConfermationScreenState extends State { child: Padding( padding: const EdgeInsets.all(8.0), child: Text( - "Estimated Delivery Date: 20 Sep 2024", + "Estimated Delivery Date: ${widget.placedOrder!.orderItems[0].createdAt}", style: GoogleFonts.roboto( fontSize: Get.width * 0.04, fontWeight: FontWeight.w400, @@ -254,25 +244,7 @@ class _OrderConfermationScreenState extends State { ), ), ), - // Row( - // mainAxisAlignment: MainAxisAlignment.center, - // children: [ - // ElevatedButton( - // onPressed:_getOrder, - // style: ElevatedButton.styleFrom( - // foregroundColor: Colors.white, - // backgroundColor: const Color(0xFF00784C), - // padding: EdgeInsets.symmetric( - // horizontal: Get.width * 0.20, - // vertical: Get.height * 0.02), - // shape: RoundedRectangleBorder( - // borderRadius: BorderRadius.circular(10), - // ), - // ), - // child: const Text("Confirm Order"), - // ), - // ], - // ), + ], ), ), diff --git a/lib/screens/order_management/order_fullfilment_screen.dart b/lib/screens/order_management/order_fullfilment_screen.dart index 5475d79..b8429f2 100644 --- a/lib/screens/order_management/order_fullfilment_screen.dart +++ b/lib/screens/order_management/order_fullfilment_screen.dart @@ -1,3 +1,4 @@ +import 'package:cheminova/models/place_order_list_model.dart'; import 'package:cheminova/models/product_model.dart'; import 'package:cheminova/screens/order_management/order_status_update_screen.dart'; import 'package:cheminova/widgets/product_card.dart'; @@ -10,8 +11,9 @@ import '../../controller/cart_controller.dart'; import '../../models/product_model1.dart'; class OrderFullfilmentScreen extends StatefulWidget { - final Product? productModel; - const OrderFullfilmentScreen({super.key,required this.productModel}); + //final Product? productModel; + PlacedOrderList? placedOrderList; + OrderFullfilmentScreen({super.key,this.placedOrderList}); @override State createState() => _OrderFullfilmentScreenState(); @@ -148,7 +150,7 @@ class _OrderFullfilmentScreenState extends State { padding: EdgeInsets.zero, itemCount: 10, itemBuilder: (context, index) => ProductCard( - productModel:widget.productModel, + placedOrderList:widget.placedOrderList, isCheckout: true, ), ), diff --git a/lib/screens/order_management/order_management_detail_screen.dart b/lib/screens/order_management/order_management_detail_screen.dart index a5ef30c..95b5b61 100644 --- a/lib/screens/order_management/order_management_detail_screen.dart +++ b/lib/screens/order_management/order_management_detail_screen.dart @@ -1,3 +1,7 @@ +import 'package:cheminova/controller/get_order_placed_controller.dart'; +import 'package:cheminova/models/oder_place_model.dart'; +import 'package:cheminova/models/order_item_model.dart'; +import 'package:cheminova/models/place_order_list_model.dart'; import 'package:cheminova/models/product_model.dart'; import 'package:cheminova/screens/order_management/order_fullfilment_screen.dart'; import 'package:cheminova/widgets/product_card.dart'; @@ -6,13 +10,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:get/get.dart'; import 'package:google_fonts/google_fonts.dart'; +import 'package:intl/intl.dart'; import '../../controller/cart_controller.dart'; import '../../models/product_model1.dart'; class OrderManagementDetailScreen extends StatefulWidget { - final Product? productModel; - const OrderManagementDetailScreen({super.key,required this.productModel}); + //final Product? productModel; + PlacedOrderList? placedOrderList; + PlacedOrderModel? placedOrderModel; + OrderManagementDetailScreen({super.key,this.placedOrderList,this.placedOrderModel}); @override State createState() => @@ -23,17 +30,45 @@ class OrderManagementDetailScreen extends StatefulWidget { class _OrderManagementDetailScreenState extends State { final CartController _cartController = Get.put(CartController()); - // final List _checkoutList = [ - // ProductModel( - // id: "1", - // image: 'assets/images/image_1.png', - // name: "Product 1", - // category: ProductCategory.food, - // description: 'Product 1 description', - // price: 100, - // ), - // ]; - @override + final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); + String formatDate(String apiDate) { + + DateTime parsedDate = DateTime.parse(apiDate); + + String formattedDate = DateFormat('dd-MMM-yyyy').format(parsedDate); + + return formattedDate; + } + String capitalizeFirstLetter(String text) { + if (text.isEmpty) return text; + return text[0].toUpperCase() + text.substring(1).toLowerCase(); + } + +Future adduni()async { + final Set uniqueOrderIds = {}; + final List uniqueOrders = []; + + for (var order in _getPlacedOrderController.placedOrders) { + if (uniqueOrderIds.add(order.id)) { + uniqueOrders.add(order); + } + } + final order = uniqueOrders[0]; + + // Combine product names into a single string + final productNames = order.orderItem + .map((item) => (item.name)) + .join(', '); + final categotyName = order.orderItem + .map((item) => (item.categoryName)) + .join(', '); + final quantity = order.orderItem + .map((item) => (item.quantity)) + .join(', '); +} + + + @override Widget build(BuildContext context) { return Scaffold( extendBodyBehindAppBar: true, @@ -102,8 +137,8 @@ class _OrderManagementDetailScreenState child: Text( "Order Summary", style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, + fontSize: Get.width * 0.05, + fontWeight: FontWeight.bold, ), ), ), @@ -113,12 +148,18 @@ class _OrderManagementDetailScreenState child: Padding( padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Text( - "Order ID: 123456", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Order ID:", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text(widget.placedOrderList!.id), + ], ), ), ), @@ -127,25 +168,37 @@ class _OrderManagementDetailScreenState child: Padding( padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Text( - "Order Date: MM/DD/YYYY", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Order Date: ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text(formatDate("${widget.placedOrderList!.createdAt}")), + ], ), ), ), SizedBox( width: Get.width, child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - "Total Price: ₹ Total", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, - ), + padding: EdgeInsets.all(8.0), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text( + "Total Amount: ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("₹ ${widget.placedOrderList!.grandTotal}"), + ], ), ), ), @@ -160,11 +213,52 @@ class _OrderManagementDetailScreenState padding: EdgeInsets.all(Get.width * 0.02), child: ListView.builder( padding: EdgeInsets.zero, - itemCount: 10, - itemBuilder: (context, index) => ProductCard( - productModel: widget.productModel, - isCheckout: true, - ), + itemCount: widget.placedOrderList?.orderItem.length ?? 0, + itemBuilder: (context, index) { + final orderItem = widget.placedOrderList!.orderItem[index]; + return orderItem != null + ? Card( + margin: const EdgeInsets.symmetric(vertical: 5.0), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10), + ), + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + children: [ + Image.asset( + "assets/images/product.png", // Add the image URL here + height: 50, + width: 50, + fit: BoxFit.cover, + ), + const SizedBox(width: 10), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Text( + capitalizeFirstLetter(orderItem.name), + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text( + "Quantity: ${orderItem.quantity}", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.03, + ), + ), + ], + ), + ), + ], + ), + ), + ) + : const SizedBox.shrink(); + }, ), ), ), @@ -192,28 +286,33 @@ class _OrderManagementDetailScreenState child: Padding( padding: const EdgeInsets.fromLTRB(8, 8, 8, 0), - child: Text( - "Address: Hyderabad", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, - ), - ), - ), - ), - SizedBox( - width: Get.width, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Text( - "Contact: +91 9123456789", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w400, - ), + child: Row( + children: [ + Text( + "Address: ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.bold, + ), + ), + Text("${widget.placedOrderList!.shipTo}") + ], ), ), ), + // SizedBox( + // width: Get.width, + // child: Padding( + // padding: const EdgeInsets.all(8.0), + // child: Text( + // "Contact: +91 9123456789", + // style: GoogleFonts.roboto( + // fontSize: Get.width * 0.04, + // fontWeight: FontWeight.w400, + // ), + // ), + // ), + // ), ], ), ), @@ -223,12 +322,17 @@ class _OrderManagementDetailScreenState width: Get.width, child: Padding( padding: const EdgeInsets.all(8), - child: Text( - "Status: Processing/ Shipped/ Delivered", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w600, - ), + child: Row( + children: [ + Text( + "Status: ", + style: GoogleFonts.roboto( + fontSize: Get.width * 0.04, + fontWeight: FontWeight.w600, + ), + ), + Text(capitalizeFirstLetter("${widget.placedOrderList!.status}")), + ], ), ), ), @@ -238,31 +342,31 @@ class _OrderManagementDetailScreenState ), ), SizedBox(height: Get.height * 0.04), - SizedBox( - width: Get.width * 0.9, - height: Get.height * 0.06, - child: ElevatedButton( - onPressed: () => Get.to( - () => OrderFullfilmentScreen( - productModel:widget.productModel , - ), - ), - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, - backgroundColor: const Color(0xFF00784C), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10), - ), - ), - child: Text( - "Fulfill Order", - style: GoogleFonts.roboto( - fontSize: Get.width * 0.04, - fontWeight: FontWeight.w600, - ), - ), - ), - ), + // SizedBox( + // width: Get.width * 0.9, + // height: Get.height * 0.06, + // child: ElevatedButton( + // onPressed: () => Get.to( + // () => OrderFullfilmentScreen( + // placedOrderList:widget.placedOrderList , + // ), + // ), + // style: ElevatedButton.styleFrom( + // foregroundColor: Colors.white, + // backgroundColor: const Color(0xFF00784C), + // shape: RoundedRectangleBorder( + // borderRadius: BorderRadius.circular(10), + // ), + // ), + // child: Text( + // "Fulfill Order", + // style: GoogleFonts.roboto( + // fontSize: Get.width * 0.04, + // fontWeight: FontWeight.w600, + // ), + // ), + // ), + // ), ], ), ), diff --git a/lib/screens/order_management/order_management_screen.dart b/lib/screens/order_management/order_management_screen.dart index a0dfda0..d8c0ae5 100644 --- a/lib/screens/order_management/order_management_screen.dart +++ b/lib/screens/order_management/order_management_screen.dart @@ -1,3 +1,4 @@ +import 'package:cheminova/models/place_order_list_model.dart'; import 'package:cheminova/screens/order_management/order_management_detail_screen.dart'; import 'package:cheminova/widgets/input_field.dart'; import 'package:cheminova/widgets/my_drawer.dart'; @@ -5,12 +6,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_svg/svg.dart'; import 'package:get/get.dart'; import 'package:google_fonts/google_fonts.dart'; - +import 'package:intl/intl.dart'; +import '../../controller/cart_controller.dart'; +import '../../controller/get_order_placed_controller.dart'; import '../../models/product_model1.dart'; + class OrderManagementScreen extends StatefulWidget { - Product? productModel; - OrderManagementScreen({super.key,this.productModel}); + final Product? productModel; + PlacedOrderList? placeOrder; + OrderManagementScreen({super.key, this.productModel, this.placeOrder}); @override State createState() => _OrderManagementScreenState(); @@ -18,10 +23,39 @@ class OrderManagementScreen extends StatefulWidget { class _OrderManagementScreenState extends State { final _searchController = TextEditingController(); - final List _filterList = [ - "Order Status", - "Date Range", - ]; + final List _filterList = ["Order Status", "Date Range"]; + + final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); + final CartController _cartController = Get.put(CartController()); + final GlobalKey _refreshIndicatorKey = + GlobalKey(); + + @override + void initState() { + super.initState(); + getOrder1(); + } + + Future _onRefresh() async { + await getOrder1(); + await Future.delayed(Duration(seconds: 1)); + } + + Future getOrder1() async { + await _getPlacedOrderController.getOrders(); + print("Order fetched successfully"); + } + + String capitalizeFirstLetter(String text) { + if (text.isEmpty) return text; + return text[0].toUpperCase() + text.substring(1).toLowerCase(); + } + + String formatDate(String apiDate) { + DateTime parsedDate = DateTime.parse(apiDate); + String formattedDate = DateFormat('dd-MMM-yyyy').format(parsedDate); + return formattedDate; + } @override Widget build(BuildContext context) { @@ -37,9 +71,7 @@ class _OrderManagementScreenState extends State { onTap: () => Scaffold.of(context).openDrawer(), child: Padding( padding: const EdgeInsets.all(16.0), - child: SvgPicture.asset( - 'assets/svg/menu.svg', - ), + child: SvgPicture.asset('assets/svg/menu.svg'), ), ); }, @@ -49,171 +81,190 @@ class _OrderManagementScreenState extends State { onTap: () => Get.back(), child: Padding( padding: const EdgeInsets.all(8.0), - child: SvgPicture.asset( - 'assets/svg/back_arrow.svg', - ), + child: SvgPicture.asset('assets/svg/back_arrow.svg'), ), ), ], - title: const Text( - "Order Management", - ), + title: const Text("Order Management"), ), drawer: const MyDrawer(), body: Stack( fit: StackFit.expand, children: [ - Image.asset( - 'assets/images/image_1.png', - fit: BoxFit.cover, - ), + Image.asset('assets/images/image_1.png', fit: BoxFit.cover), SafeArea( child: SingleChildScrollView( - child: Padding( - padding: EdgeInsets.only( - bottom: MediaQuery.of(context).viewInsets.bottom), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - InputField( - hintText: "Search Order", - labelText: "Search Order", - controller: _searchController, - ), - SizedBox(height: Get.height * 0.035), - Card( - margin: const EdgeInsets.symmetric(horizontal: 18), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(19), - side: const BorderSide(color: Color(0xFFFDFDFD)), + child: Padding( + padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), + child: RefreshIndicator( + key: _refreshIndicatorKey, + onRefresh: _onRefresh, + color: Colors.black, + backgroundColor: Colors.white, + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + InputField( + hintText: "Search Order", + labelText: "Search Order", + controller: _searchController, ), - color: const Color(0xFFB4D1E5).withOpacity(0.9), - child: Padding( - padding: const EdgeInsets.all(12.0), - child: Column( - mainAxisSize: MainAxisSize.min, - children: [ - SizedBox( - height: Get.height * 0.05, - child: ListView.builder( - shrinkWrap: true, - scrollDirection: Axis.horizontal, - itemCount: _filterList.length, - itemBuilder: (context, index) => Padding( - padding: - const EdgeInsets.symmetric(horizontal: 4), - child: Chip( - label: Text( - _filterList[index], - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.w500, + SizedBox(height: Get.height * 0.035), + Card( + margin: const EdgeInsets.symmetric(horizontal: 18), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(19), + side: const BorderSide(color: Color(0xFFFDFDFD)), + ), + color: const Color(0xFFB4D1E5).withOpacity(0.9), + child: Padding( + padding: const EdgeInsets.all(12.0), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox( + height: Get.height * 0.05, + child: ListView.builder( + shrinkWrap: true, + scrollDirection: Axis.horizontal, + itemCount: _filterList.length, + itemBuilder: (context, index) => Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: Chip( + label: Text( + _filterList[index], + style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w500), ), ), ), ), ), - ), - SizedBox( - height: Get.height * 0.6, - child: ListView.builder( - padding: EdgeInsets.zero, - shrinkWrap: true, - itemCount: 2, - itemBuilder: (context, index) => Padding( - padding: - const EdgeInsets.symmetric(vertical: 8), - child: Card( - child: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.fromLTRB( - 16, 8, 8, 0), - child: Text( - "Order ID: 123456", - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.w400, - ), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB( - 16, 8, 8, 0), - child: Text( - "Product Name: XYZ", - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.w400, - ), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB( - 16, 8, 8, 0), - child: Text( - "Order Date: MM/DD/YYYY", - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.w400, - ), - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB( - 16, 8, 8, 8), - child: Text( - "Status: Processing/shipped/delivered", - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.w400, - ), - ), - ), - SizedBox( - width: Get.width * 0.4, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - onPressed: () => Get.to( - () => - OrderManagementDetailScreen( - productModel:widget.productModel, + SizedBox( + height: Get.height * 0.6, + child: Obx(() { + // Use a set to keep track of unique order IDs + final Set uniqueOrderIds = {}; + final List uniqueOrders = []; + + for (var order in _getPlacedOrderController.placedOrders) { + if (uniqueOrderIds.add(order.id)) { + uniqueOrders.add(order); + } + } + + return ListView.builder( + padding: EdgeInsets.zero, + shrinkWrap: true, + itemCount: uniqueOrders.length, + itemBuilder: (context, index) { + final order = uniqueOrders[index]; + + // Combine product names into a single string + final productNames = order.orderItem + .map((item) => capitalizeFirstLetter(item.name)) + .join(', '); + + return Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text("${order.id}") + ], + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, // Aligns the Column to the top of the Text + children: [ + Text( + "Product Names: ", + style: GoogleFonts.roboto( + fontSize: 14, + fontWeight: FontWeight.bold, + ), ), - ), - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, - backgroundColor: - const Color(0xFF004791), - shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(10), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, // Aligns text to the right within the Column + children: [ + const SizedBox(height: 4), // Adds a small space between the label and the product names + for (int i = 0; i < productNames.split(",").length; i++) + Text( + '${i + 1}. ${productNames.split(",")[i].trim()}', // Adds index and trims whitespace + textAlign: TextAlign.left, // Aligns text to the right + style: GoogleFonts.roboto( + fontSize: 14, + ), + ), + ], + ), + ), + ], ), ), - child: Text( - "View Details", - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.w400, + + + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Order Date: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text(formatDate("${order.createdAt}")) + ], ), ), - ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Status: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text(capitalizeFirstLetter("${order.status}")) + ], + ), + ), + SizedBox( + width: Get.width * 0.4, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + onPressed: () => Get.to(() => OrderManagementDetailScreen( + placedOrderList: uniqueOrders[index])), + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: const Color(0xFF004791), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10)), + ), + child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), + ), + ), + ) + ], ), - ) - ], - ), - ), - ), - ), - ) - ], + ), + ); + }, + ); + }), + ) + ], + ), ), ), - ), - ], + ], + ), ), ), ), @@ -223,3 +274,253 @@ class _OrderManagementScreenState extends State { ); } } + + + + + + + + + + +// import 'package:cheminova/controller/get_place_order_service.dart'; +// import 'package:cheminova/controller/place_order_controller.dart'; +// import 'package:cheminova/models/place_order_list_model.dart'; +// import 'package:cheminova/screens/order_management/order_management_detail_screen.dart'; +// import 'package:cheminova/widgets/input_field.dart'; +// import 'package:cheminova/widgets/my_drawer.dart'; +// import 'package:flutter/material.dart'; +// import 'package:flutter_svg/svg.dart'; +// import 'package:get/get.dart'; +// import 'package:google_fonts/google_fonts.dart'; +// import 'package:intl/intl.dart'; +// +// import '../../controller/cart_controller.dart'; +// import '../../controller/get_order_placed_controller.dart'; +// import '../../models/product_model1.dart'; +// import '../../models/oder_place_model.dart'; +// import '../../utils/show_snackbar.dart'; // Ensure this import is correct +// +// class OrderManagementScreen extends StatefulWidget { +// final Product? productModel; +// PlacedOrderList? placeOrder; +// OrderManagementScreen({super.key, this.productModel, this.placeOrder}); +// +// @override +// State createState() => _OrderManagementScreenState(); +// } +// +// class _OrderManagementScreenState extends State { +// final _searchController = TextEditingController(); +// final List _filterList = ["Order Status", "Date Range"]; +// +// final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); +// final CartController _cartController = Get.put(CartController()); +// +// @override +// void initState() { +// super.initState(); +// getOrder1(); +// } +// +// Future getOrder1() async { +// await _getPlacedOrderController.getOrders(); +// print("Order fetched successfully"); +// } +// +// String capitalizeFirstLetter(String text) { +// if (text.isEmpty) return text; +// return text[0].toUpperCase() + text.substring(1).toLowerCase(); +// } +// +// String formatDate(String apiDate) { +// DateTime parsedDate = DateTime.parse(apiDate); +// String formattedDate = DateFormat('dd-MMM-yyyy hh:mm:ss a').format(parsedDate); +// return formattedDate; +// } +// +// @override +// Widget build(BuildContext context) { +// return Scaffold( +// extendBodyBehindAppBar: true, +// appBar: AppBar( +// centerTitle: true, +// backgroundColor: Colors.transparent, +// elevation: 0, +// leading: Builder( +// builder: (context) { +// return GestureDetector( +// onTap: () => Scaffold.of(context).openDrawer(), +// child: Padding( +// padding: const EdgeInsets.all(16.0), +// child: SvgPicture.asset('assets/svg/menu.svg'), +// ), +// ); +// }, +// ), +// actions: [ +// GestureDetector( +// onTap: () => Get.back(), +// child: Padding( +// padding: const EdgeInsets.all(8.0), +// child: SvgPicture.asset('assets/svg/back_arrow.svg'), +// ), +// ), +// ], +// title: const Text("Order Management"), +// ), +// drawer: const MyDrawer(), +// body: Stack( +// fit: StackFit.expand, +// children: [ +// Image.asset('assets/images/image_1.png', fit: BoxFit.cover), +// SafeArea( +// child: SingleChildScrollView( +// child: Padding( +// padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// mainAxisAlignment: MainAxisAlignment.start, +// children: [ +// InputField( +// hintText: "Search Order", +// labelText: "Search Order", +// controller: _searchController, +// ), +// SizedBox(height: Get.height * 0.035), +// Card( +// margin: const EdgeInsets.symmetric(horizontal: 18), +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(19), +// side: const BorderSide(color: Color(0xFFFDFDFD)), +// ), +// color: const Color(0xFFB4D1E5).withOpacity(0.9), +// child: Padding( +// padding: const EdgeInsets.all(12.0), +// child: Column( +// mainAxisSize: MainAxisSize.min, +// children: [ +// SizedBox( +// height: Get.height * 0.05, +// child: ListView.builder( +// shrinkWrap: true, +// scrollDirection: Axis.horizontal, +// itemCount: _filterList.length, +// itemBuilder: (context, index) => Padding( +// padding: const EdgeInsets.symmetric(horizontal: 4), +// child: Chip( +// label: Text( +// _filterList[index], +// style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w500), +// ), +// ), +// ), +// ), +// ), +// SizedBox( +// height: Get.height * 0.6, +// child: Obx(() { +// return ListView.builder( +// padding: EdgeInsets.zero, +// shrinkWrap: true, +// itemCount: _getPlacedOrderController.placedOrders.length, +// itemBuilder: (context, index) { +// final order = _getPlacedOrderController.placedOrders[index]; +// +// // Combine product names into a single string +// final productNames = order.orderItem +// .map((item) => capitalizeFirstLetter(item.name)) +// .join(', '); +// +// return Padding( +// padding: const EdgeInsets.symmetric(vertical: 8), +// child: Card( +// child: Column( +// crossAxisAlignment: CrossAxisAlignment.start, +// children: [ +// Padding( +// padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), +// Text("${order.id}") +// ], +// ), +// ), +// Padding( +// padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text("Product Names: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), +// Expanded( +// child: Text(productNames, +// style: GoogleFonts.roboto( +// fontSize: 14, +// )), +// ), +// ], +// ), +// ), +// Padding( +// padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text("Order Date: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), +// Text(formatDate("${order.createdAt}")) +// ], +// ), +// ), +// Padding( +// padding: const EdgeInsets.fromLTRB(16, 8, 8, 8), +// child: Row( +// mainAxisAlignment: MainAxisAlignment.spaceBetween, +// children: [ +// Text("Status: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), +// Text(capitalizeFirstLetter("${order.status}")) +// ], +// ), +// ), +// SizedBox( +// width: Get.width * 0.4, +// child: Padding( +// padding: const EdgeInsets.all(8.0), +// child: ElevatedButton( +// onPressed: () => Get.to(() => OrderManagementDetailScreen( +// placedOrderList: _getPlacedOrderController.placedOrders[index])), +// style: ElevatedButton.styleFrom( +// foregroundColor: Colors.white, +// backgroundColor: const Color(0xFF004791), +// shape: RoundedRectangleBorder( +// borderRadius: BorderRadius.circular(10)), +// ), +// child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), +// ), +// ), +// ) +// ], +// ), +// ), +// ); +// }, +// ); +// }), +// ) +// ], +// ), +// ), +// ), +// ], +// ), +// ), +// ), +// ), +// ], +// ), +// ); +// } +// } +// diff --git a/lib/screens/product/cart_screen.dart b/lib/screens/product/cart_screen.dart index 89a922a..97f40f4 100644 --- a/lib/screens/product/cart_screen.dart +++ b/lib/screens/product/cart_screen.dart @@ -62,8 +62,10 @@ class _CartScreenState extends State { ), ), ], - title: const Text( - "Cart", + title: Center( + child: const Text( + "Cart", + ), ), ), drawer: const MyDrawer(), @@ -114,11 +116,12 @@ class _CartScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - "Subtotal Price: ", + "Subtotal ", style: GoogleFonts.roboto( fontSize: 15, color: Colors.black, + fontWeight: FontWeight.bold ), ), Text("₹ ${_cartController.subtotal.value}"), @@ -136,11 +139,13 @@ class _CartScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - "gstTotal Price: ", + "GST ", style: GoogleFonts.roboto( fontSize: 15, color: Colors.black, + fontWeight: FontWeight.bold + ), ), Text("₹ ${_cartController.gstTotal.value}"), @@ -153,11 +158,12 @@ class _CartScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - "grandTotal Price:", + "Total Amount ", style: GoogleFonts.roboto( fontSize: 15, color: Colors.black, + fontWeight: FontWeight.bold ), ), Text(" ₹ ${_cartController.grandTotal.value}"), diff --git a/lib/screens/product/product_catalog_screen.dart b/lib/screens/product/product_catalog_screen.dart index 5a27415..4090e9b 100644 --- a/lib/screens/product/product_catalog_screen.dart +++ b/lib/screens/product/product_catalog_screen.dart @@ -169,8 +169,10 @@ class _ProductCatalogScreenState extends State { ), ), ], - title: const Text( - "Product Catalogue", + title: Center( + child: const Text( + "Product Catalogue", + ), ), ), drawer: const MyDrawer(), @@ -216,7 +218,7 @@ class _ProductCatalogScreenState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Text( - "Filters", + "Filter", style: GoogleFonts.poppins( fontWeight: FontWeight.bold, fontSize: 16, @@ -225,7 +227,7 @@ class _ProductCatalogScreenState extends State { TextButton( onPressed: _clearFilters, child: Text( - "Clear Filters", + "Clear Filter", style: GoogleFonts.poppins( color: Colors.red, fontSize: 14, diff --git a/lib/screens/product/product_detail_screen.dart b/lib/screens/product/product_detail_screen.dart index f725649..d58c752 100644 --- a/lib/screens/product/product_detail_screen.dart +++ b/lib/screens/product/product_detail_screen.dart @@ -24,6 +24,10 @@ class ProductDetailScreen extends StatefulWidget { class _ProductDetailScreenState extends State { final CartController _cartController = Get.put(CartController()); + String capitalizeFirstLetter(String text) { + if (text.isEmpty) return text; + return text[0].toUpperCase() + text.substring(1).toLowerCase(); + } @override Widget build(BuildContext context) { return Scaffold( @@ -92,7 +96,7 @@ class _ProductDetailScreenState extends State { padding: const EdgeInsets.all(8.0), child: Container( height: Get.height * 0.4, - width: Get.width * 0.7, + width: Get.width * 0.8, decoration: BoxDecoration( border: Border.all( width: 4, @@ -112,47 +116,70 @@ class _ProductDetailScreenState extends State { ), Padding( padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text( - widget.productModel!.name, - style: GoogleFonts.roboto( - fontSize: 20, - fontWeight: FontWeight.w600, - color: Colors.white, - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("Product Name ",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),), + Text( + capitalizeFirstLetter(widget.productModel!.name), + style: GoogleFonts.roboto( + fontSize: 16, + // fontWeight: FontWeight.w600, + color: Colors.black, + ), + ), + ], ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text( - "₹ ${widget.productModel!.price.toString()}", - style: GoogleFonts.roboto( - fontSize: 24, - fontWeight: FontWeight.w800, - color: Colors.white, - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("Price ",style: TextStyle(fontSize: 16,fontWeight: FontWeight.bold),), + Text( + "₹ ${widget.productModel!.price.toString()}", + style: GoogleFonts.roboto( + fontSize: 16, + //fontWeight: FontWeight.w800, + color: Colors.black, + ), + ), + ], ), ), Padding( padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text( - widget.productModel!.category!.categoryName, - style: GoogleFonts.roboto( - fontSize: 16, - fontWeight: FontWeight.w400, - color: Colors.white, - ), + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + Text("Category ",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),), + Text( + capitalizeFirstLetter(widget.productModel!.category!.categoryName), + style: GoogleFonts.roboto( + fontSize: 16, + fontWeight: FontWeight.w400, + color: Colors.black, + ), + ), + ], ), ), const SizedBox(height: 8), Padding( padding: const EdgeInsets.symmetric(horizontal: 8), - child: Text( - widget.productModel!.description, - style: GoogleFonts.roboto( - fontSize: 16, - fontWeight: FontWeight.w400, - color: Colors.white, - ), + child: Row( + children: [ + Text("Description",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16)), + Text( + capitalizeFirstLetter(widget.productModel!.description), + style: GoogleFonts.roboto( + fontSize: 16, + fontWeight: FontWeight.w400, + color: Colors.black, + ), + ), + ], ), ), ], @@ -167,7 +194,7 @@ class _ProductDetailScreenState extends State { onPressed: () { // Pass the product data to the CartScreen _cartController.addToCart(widget.productModel!); - showSnackbar("Product Added to cart"); + showSnackbar("Product successfully added to your cart"); }, style: ElevatedButton.styleFrom( foregroundColor: Colors.white, diff --git a/lib/utils/constants.dart b/lib/utils/constants.dart index ab75e1f..2f1ac98 100644 --- a/lib/utils/constants.dart +++ b/lib/utils/constants.dart @@ -1 +1,3 @@ -String baseUrl = "https://cheminova-api-2.onrender.com"; +//String baseUrl = "https://cheminova-api-2.onrender.com"; + +String baseUrl = "https://api.cnapp.co.in"; \ No newline at end of file diff --git a/lib/widgets/product_card.dart b/lib/widgets/product_card.dart index 89a9458..8718634 100644 --- a/lib/widgets/product_card.dart +++ b/lib/widgets/product_card.dart @@ -1,5 +1,7 @@ import 'package:cheminova/controller/cart_controller.dart'; import 'package:cheminova/models/oder_place_model.dart'; +import 'package:cheminova/models/order_item_model.dart'; +import 'package:cheminova/models/place_order_list_model.dart'; import 'package:cheminova/models/product_model.dart'; import 'package:cheminova/screens/product/product_detail_screen.dart'; import 'package:flutter/material.dart'; @@ -13,17 +15,22 @@ import '../utils/show_snackbar.dart'; class ProductCard extends StatefulWidget { final Product? productModel; PlacedOrderModel? placedOrder; + PlacedOrderList? placedOrderList; + PlaceOrderItem1? placeorderItem; ProductModel? product; final bool isInCart; final bool isCheckout; final bool isConfirmation; - int? quantity; + int? quantity; + ProductCard({ super.key, this.product, - this.quantity=1, + this.quantity = 1, this.productModel, this.placedOrder, + this.placedOrderList, + this.placeorderItem, this.isInCart = false, this.isCheckout = false, this.isConfirmation = false, @@ -33,25 +40,26 @@ class ProductCard extends StatefulWidget { State createState() => _ProductCardState(); } - class _ProductCardState extends State { - @override + String capitalizeFirstLetter(String text) { + if (text.isEmpty) return text; + return text[0].toUpperCase() + text.substring(1).toLowerCase(); + } @override Widget build(BuildContext context) { final CartController _cartController = Get.put(CartController()); bool showQuantity = widget.isInCart || widget.isCheckout || widget.isConfirmation; - bool isProductInCart = _cartController.cartList.contains(widget.productModel); - + bool isProductInCart = _cartController.cartList.any((p) => p.id == widget.productModel!.id); int currentQuantity = isProductInCart ? _cartController.cartList.firstWhere((p) => p.id == widget.productModel!.id).quantity : widget.productModel!.quantity; + return GestureDetector( onTap: () => widget.isInCart || widget.isCheckout ? null - : Get.to(() => - ProductDetailScreen(productModel: widget.productModel)), + : Get.to(() => ProductDetailScreen(productModel: widget.productModel)), child: Card( child: Row( children: [ @@ -65,7 +73,6 @@ class _ProductCardState extends State { decoration: BoxDecoration( image: DecorationImage( image: AssetImage("assets/images/product.png"), - // Image.asset(productModel!['image']).image, fit: BoxFit.cover, ), ), @@ -79,21 +86,21 @@ class _ProductCardState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( - widget.productModel!.name, + capitalizeFirstLetter(widget.productModel!.name), style: GoogleFonts.roboto( fontSize: 16, fontWeight: FontWeight.w500, ), ), Text( - widget.productModel!.category!.categoryName, + capitalizeFirstLetter(widget.productModel!.category!.categoryName), style: GoogleFonts.roboto( fontSize: 14, fontWeight: FontWeight.w400, ), ), Text( - "₹ ${ widget.productModel!.price.toString()}", + "₹ ${widget.productModel!.price.toString()}", style: GoogleFonts.roboto( fontSize: 22, fontWeight: FontWeight.w700, @@ -122,8 +129,7 @@ class _ProductCardState extends State { borderRadius: BorderRadius.circular(10), ), child: Row( - mainAxisAlignment: - MainAxisAlignment.spaceAround, + mainAxisAlignment: MainAxisAlignment.spaceAround, children: [ SizedBox( height: 24, @@ -132,20 +138,16 @@ class _ProductCardState extends State { onPressed: () { _cartController.decreaseQuantity(widget.productModel!); setState(() { - // Update the local quantity to reflect the change currentQuantity = _cartController .cartList - .firstWhere((p) => - p.id == - widget.productModel!.id) + .firstWhere((p) => p.id == widget.productModel!.id) .quantity; }); }, style: ElevatedButton.styleFrom( padding: EdgeInsets.zero, shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(8.0), + borderRadius: BorderRadius.circular(8.0), ), ), child: Text( @@ -158,7 +160,7 @@ class _ProductCardState extends State { ), ), Text( - "${currentQuantity}", + "${currentQuantity}", style: const TextStyle( color: Colors.white, fontSize: 16, @@ -171,20 +173,16 @@ class _ProductCardState extends State { onPressed: () { _cartController.increaseQuantity(widget.productModel!); setState(() { - // Update the local quantity to reflect the change currentQuantity = _cartController .cartList - .firstWhere((p) => - p.id == - widget.productModel!.id) + .firstWhere((p) => p.id == widget.productModel!.id) .quantity; }); }, style: ElevatedButton.styleFrom( padding: EdgeInsets.zero, shape: RoundedRectangleBorder( - borderRadius: - BorderRadius.circular(8.0), + borderRadius: BorderRadius.circular(8.0), ), ), child: Text( @@ -199,13 +197,14 @@ class _ProductCardState extends State { ], ), ), - SizedBox(width: 20.0,), + SizedBox( + width: 20.0, + ), IconButton( onPressed: () { _cartController.removeFromCart(widget.productModel!); - showSnackbar("Product removed successfully!"); + showSnackbar("Product has been removed successfully!"); setState(() { - // Update the local quantity currentQuantity = 1; }); }, @@ -222,14 +221,16 @@ class _ProductCardState extends State { showSnackbar("Product already added to cart"); } else { _cartController.addToCart(widget.productModel!); - showSnackbar("Product added to cart successfully"); + showSnackbar("Product successfully added to your cart"); + // setState(() { + // currentQuantity = widget.productModel!.quantity; + // }); } }, style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: const Color(0xFF00784C), - padding: const EdgeInsets.symmetric( - horizontal: 18, vertical: 8), + padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 8), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30), ), diff --git a/pubspec.lock b/pubspec.lock index 3c7209e..b1fbc8c 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -176,6 +176,14 @@ packages: url: "https://pub.dev" source: hosted version: "4.0.2" + intl: + dependency: "direct main" + description: + name: intl + sha256: d6f56758b7d3014a48af9701c085700aac781a92a87a62b1333b46d8879661cf + url: "https://pub.dev" + source: hosted + version: "0.19.0" leak_tracker: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 2f48db9..7cc76b3 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,6 +43,7 @@ dependencies: shared_preferences: ^2.2.3 logger: ^2.4.0 get_storage: ^2.1.1 + intl: ^0.19.0 dev_dependencies: flutter_test: