1)get all Place Order api integration done

2) single Place order api integration done
3) Refresh inidicator added
4)Caps Functionality added
This commit is contained in:
saritabirare 2024-09-11 12:24:48 +05:30
parent e1d96ee34e
commit 174d7afa99
19 changed files with 1183 additions and 603 deletions

View File

@ -1,40 +1,63 @@
import 'package:cheminova/controller/get_place_order_service.dart'; import 'package:cheminova/controller/get_single_placed_order_service.dart';
import 'package:cheminova/controller/product_service.dart'; import 'package:cheminova/controller/place_order_controller.dart';
import 'package:cheminova/models/oder_place_model.dart'; import 'package:cheminova/models/place_order_list_model.dart';
import 'package:cheminova/models/product_model1.dart';
import 'package:get/get.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 { class GetPlacedOrderController extends GetxController {
final GetOrderPlacedServcie _getOrderPlacedServcie = GetOrderPlacedServcie(); final GetOrderPlacedService _getOrderPlacedService = GetOrderPlacedService();
var products = <PlacedOrderModel>[].obs; final OrderPlacedController _orderPlacedController = Get.put(OrderPlacedController());
final GetSingleOrderPlacedService _getSingleOrderPlacedService = GetSingleOrderPlacedService();
var placedOrders = <PlacedOrderList>[].obs;
var products = <Product>[].obs;
int _currentPage = 1; var isLoading = false.obs;
bool isLoading = false;
@override @override
void onInit() { void onInit() {
super.onInit(); super.onInit();
getOrders(); // Fetch the orders immediately on initialization
} }
Future<void> getOrder(String id) async { Future<void> getOrders() async {
if (isLoading) return;
isLoading = true; 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<void> searchOrder() async {
try { try {
isLoading.value = true;
final fetchedProducts = await _getOrderPlacedServcie.getPlacedOrder(); final order = await _getSingleOrderPlacedService.getSinglePlacedOrder(placedOrders[0].id);
if (order != null) {
placedOrders.clear(); // Clear existing orders if needed
if (fetchedProducts != null) { placedOrders.add(order);
} else {
products.addAll(fetchedProducts); // Handle order not found case
} }
} catch (e) { } catch (e) {
print("Error fetching products: $e"); // Handle exceptions
} finally { } finally {
isLoading = false; isLoading.value = false;
update();
} }
} }
// Optional: Reset the pagination if needed
void resetPagination() {
_getOrderPlacedService.resetPagination();
placedOrders.clear(); // Clear existing data
getOrders(); // Fetch fresh data
}
} }

View File

@ -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/common_api_service.dart';
import '../utils/show_snackbar.dart'; import '../utils/show_snackbar.dart';
class GetOrderPlacedServcie{ class GetOrderPlacedService {
Future<List<PlacedOrderModel>?> getPlacedOrder() async { int _currentPage = 1; // Initialize with the first page
//int _limit = 100; // Start with a fixed limit, can be adjusted
final List<PlacedOrderList> _allOrders = []; // To store all fetched orders
bool _hasMoreOrders = true; // To check if there are more orders to fetch
Future<List<PlacedOrderList>?> getPlacedOrders() async {
try { 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<List<PlacedOrderList>>(
method: "GET",
url: url,
fromJson: (json) {
if (json['plcaedOrders'] != null) {
final List<PlacedOrderList> orders = (json['plcaedOrders'] as List)
.map((orderJson) => PlacedOrderList.fromJson(orderJson as Map<String, dynamic>))
.toList();
final response = await commonApiService<List<PlacedOrderModel>>( if (orders.isNotEmpty) {
method: "GET", _allOrders.addAll(orders);
url: url, _currentPage++;
fromJson: (json) { // _limit += orders.length; // Adjust limit based on the number of fetched orders
if (json['plcaedOrders'] != null) { } else {
final List<PlacedOrderModel> products = (json['plcaedOrders'] as List) _hasMoreOrders = false; // Stop fetching if no more orders are returned
.map((productJson) => PlacedOrderModel.fromJson(productJson as Map<String, dynamic>)) }
.toList();
return products; return orders;
} else { } else {
return []; _hasMoreOrders = false; // Stop if there are no orders at all
} return [];
}, }
); },
return response; );
if (response == null || response.isEmpty) {
_hasMoreOrders = false; // Stop fetching if the response is empty
}
}
return _allOrders;
} catch (e) { } catch (e) {
showSnackbar(e.toString()); showSnackbar(e.toString());
return null; 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<PlacedOrderList> _allOrders = [];
// int? totalOrders ;
// Future<List<PlacedOrderList>?> 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<List<PlacedOrderList>>(
// method: "GET",
// url: url,
// fromJson: (json) {
// if (json['plcaedOrders'] != null) {
// final List<PlacedOrderList> orders = (json['plcaedOrders'] as List)
// .map((orderJson) => PlacedOrderList.fromJson(orderJson as Map<String, dynamic>))
// .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;
// }
// }

View File

@ -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<PlacedOrderList?> 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<PlacedOrderList>(
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<String, dynamic>);
} else {
throw Exception("Order not found"); // Throw an exception if not found
}
},
);
return response;
} catch (e) {
showSnackbar(e.toString());
return null;
}
}
}

View File

@ -12,9 +12,9 @@ class OrderPlacedService {
Future<void> placeOrder(PlacedOrderModel orderDetails, String token) async { Future<void> placeOrder(PlacedOrderModel orderDetails, String token) async {
//try { //try {
logger.w("orderjson ${jsonEncode(orderDetails.toJson())}"); // logger.w("orderjson ${jsonEncode(orderDetails.toJson())}");
final response = await dio.post( 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()), data: jsonEncode(orderDetails.toJson()),
options: Options( options: Options(
headers: { headers: {
@ -23,7 +23,7 @@ class OrderPlacedService {
}, },
), ),
); );
logger.w("Status code,${response.statusCode}"); //logger.w("Status code,${response.statusCode}");
if (response.statusCode != 201) { if (response.statusCode != 201) {
throw Exception('Failed to place order'); throw Exception('Failed to place order');

View File

@ -139,45 +139,3 @@ class OrderItem {
} }
} }
// class Brand {
// String id;
// String brandName;
//
// Brand({
// required this.id,
// required this.brandName,
// });
//
// factory Brand.fromJson(Map<String, dynamic> json) => Brand(
// id: json["_id"],
// brandName: json["brandName"],
// );
//
// Map<String, dynamic> toJson() => {
// "_id": id,
// "brandName": brandName,
// };
// }
//
// class Category {
// String id;
// String categoryName;
//
// Category({
// required this.id,
// required this.categoryName,
// });
//
// factory Category.fromJson(Map<String, dynamic> json) => Category(
// id: json["_id"],
// categoryName: json["categoryName"],
// );
//
// Map<String, dynamic> toJson() => {
// "_id": id,
// "categoryName": categoryName,
// };
// }

View File

@ -1,130 +1,51 @@
// import 'brand_model.dart'; class PlaceOrderItem1 {
// import 'category_model.dart'; final String sku;
// String? id;
// class OrderItem { List<String>? image;
// final String id; final String name;
// final String sku; final String categoryName;
// final String name; final String brandName;
// final Category category; final double price;
// final Brand brand; final int quantity;
// final double price;
// final double gst; PlaceOrderItem1({
// final int hsnCode; required this.sku,
// final String description; this.id,
// final String productStatus; this.image,
// final String addedBy; required this.name,
// final List<String> image; required this.categoryName,
// final DateTime createdAt; required this.brandName,
// final DateTime updatedAt; required this.price,
// final int count; required this.quantity,
// });
// OrderItem({
// required this.id, factory PlaceOrderItem1.fromJson(Map<String, dynamic> json) {
// required this.sku, return PlaceOrderItem1(
// required this.name, id: json['id'],
// required this.category, sku: json['SKU'],
// required this.brand, name: json['name'],
// required this.price, categoryName: json['categoryName'],
// required this.gst, brandName: json['brandName'],
// required this.hsnCode, price: json['price'].toDouble(),
// required this.description, quantity: json['quantity'], image: null,
// required this.productStatus, );
// required this.addedBy, }
// required this.image,
// required this.createdAt, Map<String, dynamic> toJson() {
// required this.updatedAt, return {
// required this.count, 'SKU': sku,
// }); 'name': name,
// 'categoryName': categoryName,
// factory OrderItem.fromJson(Map<String, dynamic> json) { 'brandName': brandName,
// return OrderItem( 'price': price,
// id: json['_id'], 'quantity': quantity,
// sku: json['SKU'], };
// name: json['name'], }
// category: Category.fromJson(json['category']),
// brand: Brand.fromJson(json['brand']), @override
// price: json['price'].toDouble(), String toString() {
// gst: json['GST'].toDouble(), return 'OrderItem(sku: $sku, name: $name, categoryName: $categoryName, '
// hsnCode: json['HSN_Code'], 'brandName: $brandName, price: $price, quantity: $quantity)';
// description: json['description'], }
// productStatus: json['product_Status'], }
// addedBy: json['addedBy'],
// image: List<String>.from(json['image'] ?? []),
// createdAt: DateTime.parse(json['createdAt']),
// updatedAt: DateTime.parse(json['updatedAt']),
// count: json['count'],
// );
// }
//
// Map<String, dynamic> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> json) {
// // return AddedBy(
// // id: json['_id'],
// // name: json['name'],
// // );
// // }
// // }

View File

@ -0,0 +1,136 @@
class PlacedOrderList {
final String id;
final String paymentMode;
final String shipTo;
final String billTo;
final List<OrderItem1> 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<String, dynamic> 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<String, dynamic> 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<String, dynamic> json) {
return OrderItem1(
sku: json['SKU'],
name: json['name'],
categoryName: json['categoryName'],
brandName: json['brandName'],
price: json['price'].toDouble(),
quantity: json['quantity'],
);
}
Map<String, dynamic> 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)';
}
}

View File

@ -24,9 +24,9 @@ import 'order_confermation_screen.dart';
class CheckoutScreen extends StatefulWidget { class CheckoutScreen extends StatefulWidget {
final Product? productModel; final Product? productModel;
PlacedOrderModel? placeOrder; PlacedOrderModel? placeOrder;
List<Product>? selectedProducts;
CheckoutScreen({super.key, this.productModel, this.placeOrder}); CheckoutScreen({super.key, this.productModel, this.placeOrder,this.selectedProducts});
@override @override
State<CheckoutScreen> createState() => _CheckoutScreenState(); State<CheckoutScreen> createState() => _CheckoutScreenState();
@ -37,7 +37,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
final ProductService _productService = ProductService(); final ProductService _productService = ProductService();
final ProductController _productController = Get.put(ProductController()); final ProductController _productController = Get.put(ProductController());
final OrderPlacedController _orderPlacedController = final OrderPlacedController _orderPlacedController =
Get.put(OrderPlacedController()); Get.put(OrderPlacedController());
final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController()); final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController());
int currentPage = 1; int currentPage = 1;
@ -55,7 +55,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
// _getOrder(); // _getOrder();
_loadSelectedAddress(); _loadSelectedAddress();
_loadSelectedPaymentMode(); _loadSelectedPaymentMode();
@ -137,8 +137,8 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
count: product.quantity, count: product.quantity,
//category:product.category, //category:product.category,
category:Category(id: product.category.id, categoryName: product.category.categoryName), category:Category(id: product.category.id, categoryName: product.category.categoryName),
// brand:product.brand, // brand:product.brand,
brand:Brand(id: product.brand.id, brandName: product.brand.brandName), brand:Brand(id: product.brand.id, brandName: product.brand.brandName),
v: 0, addedBy: product.addedBy, v: 0, addedBy: product.addedBy,
); );
}).toList(); }).toList();
@ -157,7 +157,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
await _orderPlacedController.placeOrder(); await _orderPlacedController.placeOrder();
if (_orderPlacedController.isLoading.value) { if (_orderPlacedController.isLoading.value) {
showSnackbar("OderPlaced Successfully"); showSnackbar("Order Placed Successfully");
Get.to(() => OrderConfermationScreen( Get.to(() => OrderConfermationScreen(
placedOrder: _orderPlacedController.placedOrder1.value, placedOrder: _orderPlacedController.placedOrder1.value,
)); ));
@ -165,7 +165,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
} catch (e) { } catch (e) {
print("PlaceOrderScreen error: $e"); print("PlaceOrderScreen error: $e");
} }
} }
@ -292,7 +292,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
SizedBox( SizedBox(
height: Get.height * 0.035, height: Get.height * 0.035,
child: RadioListTile( child: RadioListTile(
title: const Text("cheque"), title: const Text("Cheque"),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
value: "cheque", value: "cheque",
groupValue: _groupValue, groupValue: _groupValue,
@ -302,7 +302,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
SizedBox( SizedBox(
height: Get.height * 0.035, height: Get.height * 0.035,
child: RadioListTile( child: RadioListTile(
title: const Text("online-transfer"), title: const Text("Online transfer"),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
value: "online-transfer", value: "online-transfer",
groupValue: _groupValue, groupValue: _groupValue,
@ -311,7 +311,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
), ),
SizedBox( SizedBox(
child: RadioListTile( child: RadioListTile(
title: const Text("credit"), title: const Text("Credit"),
contentPadding: EdgeInsets.zero, contentPadding: EdgeInsets.zero,
value: "credit", value: "credit",
groupValue: _groupValue, groupValue: _groupValue,
@ -345,20 +345,20 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
itemCount: _cartController.cartList.length, itemCount: _cartController.cartList.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final cartItem = final cartItem =
_cartController.cartList[index]; _cartController.cartList[index];
return ProductCard( return ProductCard(
productModel:_cartController.cartList[index] , productModel:_cartController.cartList[index] ,
isCheckout: true, isCheckout: true,
quantity: _cartController.cartList[0].quantity, quantity: _cartController.cartList[0].quantity,
// ListTile( // ListTile(
// title: Text(cartItem.name ?? 'N/A'), // title: Text(cartItem.name ?? 'N/A'),
// subtitle: Text( // subtitle: Text(
// 'Quantity: ${cartItem.quantity}'), // 'Quantity: ${cartItem.quantity}'),
// trailing: Text( // trailing: Text(
// 'Price: \${cartItem.price.toStringAsFixed(2)}'), // 'Price: \${cartItem.price.toStringAsFixed(2)}'),
// ); // );
);}, );},
), ),
), ),
@ -369,30 +369,29 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('Subtotal:'), Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.subtotal.value.toStringAsFixed(2)}'), Text('${_cartController.subtotal.value.toStringAsFixed(2)}'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('GST:'), Text('GST',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'), Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('Grand Total:'), Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'), Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'),
], ],
), ),
], ],
), ),
), ),
], ],
), ),
), ),
@ -428,4 +427,4 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
), ),
); );
} }
} }

View File

@ -38,11 +38,11 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
// ), // ),
// ]; // ];
void _getOrder(){ // void _getOrder(){
final details = _getPlacedOrderController.getOrder(_cartController.cartList[0].id); // final details = _getPlacedOrderController.getOrder();
showSnackbar("Get Placed Order Sucessfully"); // showSnackbar("Get Placed Order Sucessfully");
print("dffgfg,$details"); // print("dffgfg,$details");
} // }
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final orderItems = _placedController.placedOrder1; final orderItems = _placedController.placedOrder1;
@ -128,7 +128,7 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
'Order Summary', 'Order Summary',
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.04, fontSize: Get.width * 0.04,
fontWeight: FontWeight.w500, fontWeight: FontWeight.bold,
color: Colors.black, color: Colors.black,
), ),
), ),
@ -160,21 +160,21 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('Subtotal:'), Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.subtotal.value.toStringAsFixed(2)}'), Text('${_cartController.subtotal.value.toStringAsFixed(2)}'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('GST:'), Text('GST',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'), Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'),
], ],
), ),
Row( Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text('Grand Total:'), Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'), Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'),
], ],
), ),
@ -219,18 +219,8 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
), ),
), ),
), ),
// Padding(
// padding: const EdgeInsets.all(8.0), ]),
// child: Text(
// "Contact: +91 9123456789",
// style: GoogleFonts.roboto(
// fontSize: Get.width * 0.04,
// fontWeight: FontWeight.w400,
// ),
// ),
// ),
],
),
), ),
), ),
Card( Card(
@ -240,7 +230,7 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Text( child: Text(
"Estimated Delivery Date: 20 Sep 2024", "Estimated Delivery Date: ${widget.placedOrder!.orderItems[0].createdAt}",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.04, fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
@ -254,25 +244,7 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
), ),
), ),
), ),
// 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"),
// ),
// ],
// ),
], ],
), ),
), ),

View File

@ -1,3 +1,4 @@
import 'package:cheminova/models/place_order_list_model.dart';
import 'package:cheminova/models/product_model.dart'; import 'package:cheminova/models/product_model.dart';
import 'package:cheminova/screens/order_management/order_status_update_screen.dart'; import 'package:cheminova/screens/order_management/order_status_update_screen.dart';
import 'package:cheminova/widgets/product_card.dart'; import 'package:cheminova/widgets/product_card.dart';
@ -10,8 +11,9 @@ import '../../controller/cart_controller.dart';
import '../../models/product_model1.dart'; import '../../models/product_model1.dart';
class OrderFullfilmentScreen extends StatefulWidget { class OrderFullfilmentScreen extends StatefulWidget {
final Product? productModel; //final Product? productModel;
const OrderFullfilmentScreen({super.key,required this.productModel}); PlacedOrderList? placedOrderList;
OrderFullfilmentScreen({super.key,this.placedOrderList});
@override @override
State<OrderFullfilmentScreen> createState() => _OrderFullfilmentScreenState(); State<OrderFullfilmentScreen> createState() => _OrderFullfilmentScreenState();
@ -148,7 +150,7 @@ class _OrderFullfilmentScreenState extends State<OrderFullfilmentScreen> {
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemCount: 10, itemCount: 10,
itemBuilder: (context, index) => ProductCard( itemBuilder: (context, index) => ProductCard(
productModel:widget.productModel, placedOrderList:widget.placedOrderList,
isCheckout: true, isCheckout: true,
), ),
), ),

View File

@ -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/models/product_model.dart';
import 'package:cheminova/screens/order_management/order_fullfilment_screen.dart'; import 'package:cheminova/screens/order_management/order_fullfilment_screen.dart';
import 'package:cheminova/widgets/product_card.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:flutter_svg/svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart'; import 'package:google_fonts/google_fonts.dart';
import 'package:intl/intl.dart';
import '../../controller/cart_controller.dart'; import '../../controller/cart_controller.dart';
import '../../models/product_model1.dart'; import '../../models/product_model1.dart';
class OrderManagementDetailScreen extends StatefulWidget { class OrderManagementDetailScreen extends StatefulWidget {
final Product? productModel; //final Product? productModel;
const OrderManagementDetailScreen({super.key,required this.productModel}); PlacedOrderList? placedOrderList;
PlacedOrderModel? placedOrderModel;
OrderManagementDetailScreen({super.key,this.placedOrderList,this.placedOrderModel});
@override @override
State<OrderManagementDetailScreen> createState() => State<OrderManagementDetailScreen> createState() =>
@ -23,17 +30,45 @@ class OrderManagementDetailScreen extends StatefulWidget {
class _OrderManagementDetailScreenState class _OrderManagementDetailScreenState
extends State<OrderManagementDetailScreen> { extends State<OrderManagementDetailScreen> {
final CartController _cartController = Get.put(CartController()); final CartController _cartController = Get.put(CartController());
// final List<ProductModel> _checkoutList = [ final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController());
// ProductModel( String formatDate(String apiDate) {
// id: "1",
// image: 'assets/images/image_1.png', DateTime parsedDate = DateTime.parse(apiDate);
// name: "Product 1",
// category: ProductCategory.food, String formattedDate = DateFormat('dd-MMM-yyyy').format(parsedDate);
// description: 'Product 1 description',
// price: 100, return formattedDate;
// ), }
// ]; String capitalizeFirstLetter(String text) {
@override if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase();
}
Future<void> adduni()async {
final Set<String> uniqueOrderIds = {};
final List<PlacedOrderList> 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) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
extendBodyBehindAppBar: true, extendBodyBehindAppBar: true,
@ -102,8 +137,8 @@ class _OrderManagementDetailScreenState
child: Text( child: Text(
"Order Summary", "Order Summary",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.04, fontSize: Get.width * 0.05,
fontWeight: FontWeight.w400, fontWeight: FontWeight.bold,
), ),
), ),
), ),
@ -113,12 +148,18 @@ class _OrderManagementDetailScreenState
child: Padding( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text( child: Row(
"Order ID: 123456", mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: GoogleFonts.roboto( children: [
fontSize: Get.width * 0.04, Text(
fontWeight: FontWeight.w400, "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( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text( child: Row(
"Order Date: MM/DD/YYYY", mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: GoogleFonts.roboto( children: [
fontSize: Get.width * 0.04, Text(
fontWeight: FontWeight.w400, "Order Date: ",
), style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text(formatDate("${widget.placedOrderList!.createdAt}")),
],
), ),
), ),
), ),
SizedBox( SizedBox(
width: Get.width, width: Get.width,
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: EdgeInsets.all(8.0),
child: Text( child: Row(
"Total Price: ₹ Total", mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: GoogleFonts.roboto( children: [
fontSize: Get.width * 0.04, Text(
fontWeight: FontWeight.w400, "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), padding: EdgeInsets.all(Get.width * 0.02),
child: ListView.builder( child: ListView.builder(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemCount: 10, itemCount: widget.placedOrderList?.orderItem.length ?? 0,
itemBuilder: (context, index) => ProductCard( itemBuilder: (context, index) {
productModel: widget.productModel, final orderItem = widget.placedOrderList!.orderItem[index];
isCheckout: true, 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( child: Padding(
padding: padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0), const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Text( child: Row(
"Address: Hyderabad", children: [
style: GoogleFonts.roboto( Text(
fontSize: Get.width * 0.04, "Address: ",
fontWeight: FontWeight.w400, style: GoogleFonts.roboto(
), fontSize: Get.width * 0.04,
), fontWeight: FontWeight.bold,
), ),
), ),
SizedBox( Text("${widget.placedOrderList!.shipTo}")
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,
),
), ),
), ),
), ),
// 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, width: Get.width,
child: Padding( child: Padding(
padding: const EdgeInsets.all(8), padding: const EdgeInsets.all(8),
child: Text( child: Row(
"Status: Processing/ Shipped/ Delivered", children: [
style: GoogleFonts.roboto( Text(
fontSize: Get.width * 0.04, "Status: ",
fontWeight: FontWeight.w600, 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(height: Get.height * 0.04),
SizedBox( // SizedBox(
width: Get.width * 0.9, // width: Get.width * 0.9,
height: Get.height * 0.06, // height: Get.height * 0.06,
child: ElevatedButton( // child: ElevatedButton(
onPressed: () => Get.to( // onPressed: () => Get.to(
() => OrderFullfilmentScreen( // () => OrderFullfilmentScreen(
productModel:widget.productModel , // placedOrderList:widget.placedOrderList ,
), // ),
), // ),
style: ElevatedButton.styleFrom( // style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, // foregroundColor: Colors.white,
backgroundColor: const Color(0xFF00784C), // backgroundColor: const Color(0xFF00784C),
shape: RoundedRectangleBorder( // shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10), // borderRadius: BorderRadius.circular(10),
), // ),
), // ),
child: Text( // child: Text(
"Fulfill Order", // "Fulfill Order",
style: GoogleFonts.roboto( // style: GoogleFonts.roboto(
fontSize: Get.width * 0.04, // fontSize: Get.width * 0.04,
fontWeight: FontWeight.w600, // fontWeight: FontWeight.w600,
), // ),
), // ),
), // ),
), // ),
], ],
), ),
), ),

View File

@ -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/screens/order_management/order_management_detail_screen.dart';
import 'package:cheminova/widgets/input_field.dart'; import 'package:cheminova/widgets/input_field.dart';
import 'package:cheminova/widgets/my_drawer.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:flutter_svg/svg.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.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/product_model1.dart';
class OrderManagementScreen extends StatefulWidget { class OrderManagementScreen extends StatefulWidget {
Product? productModel; final Product? productModel;
OrderManagementScreen({super.key,this.productModel}); PlacedOrderList? placeOrder;
OrderManagementScreen({super.key, this.productModel, this.placeOrder});
@override @override
State<OrderManagementScreen> createState() => _OrderManagementScreenState(); State<OrderManagementScreen> createState() => _OrderManagementScreenState();
@ -18,10 +23,39 @@ class OrderManagementScreen extends StatefulWidget {
class _OrderManagementScreenState extends State<OrderManagementScreen> { class _OrderManagementScreenState extends State<OrderManagementScreen> {
final _searchController = TextEditingController(); final _searchController = TextEditingController();
final List<String> _filterList = [ final List<String> _filterList = ["Order Status", "Date Range"];
"Order Status",
"Date Range", final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController());
]; final CartController _cartController = Get.put(CartController());
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
GlobalKey<RefreshIndicatorState>();
@override
void initState() {
super.initState();
getOrder1();
}
Future<void> _onRefresh() async {
await getOrder1();
await Future.delayed(Duration(seconds: 1));
}
Future<void> 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 @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -37,9 +71,7 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
onTap: () => Scaffold.of(context).openDrawer(), onTap: () => Scaffold.of(context).openDrawer(),
child: Padding( child: Padding(
padding: const EdgeInsets.all(16.0), padding: const EdgeInsets.all(16.0),
child: SvgPicture.asset( child: SvgPicture.asset('assets/svg/menu.svg'),
'assets/svg/menu.svg',
),
), ),
); );
}, },
@ -49,171 +81,190 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
onTap: () => Get.back(), onTap: () => Get.back(),
child: Padding( child: Padding(
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: SvgPicture.asset( child: SvgPicture.asset('assets/svg/back_arrow.svg'),
'assets/svg/back_arrow.svg',
),
), ),
), ),
], ],
title: const Text( title: const Text("Order Management"),
"Order Management",
),
), ),
drawer: const MyDrawer(), drawer: const MyDrawer(),
body: Stack( body: Stack(
fit: StackFit.expand, fit: StackFit.expand,
children: [ children: [
Image.asset( Image.asset('assets/images/image_1.png', fit: BoxFit.cover),
'assets/images/image_1.png',
fit: BoxFit.cover,
),
SafeArea( SafeArea(
child: SingleChildScrollView( child: SingleChildScrollView(
child: Padding( child: Padding(
padding: EdgeInsets.only( padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
bottom: MediaQuery.of(context).viewInsets.bottom), child: RefreshIndicator(
child: Column( key: _refreshIndicatorKey,
mainAxisSize: MainAxisSize.min, onRefresh: _onRefresh,
mainAxisAlignment: MainAxisAlignment.start, color: Colors.black,
children: [ backgroundColor: Colors.white,
InputField( child: Column(
hintText: "Search Order", mainAxisSize: MainAxisSize.min,
labelText: "Search Order", mainAxisAlignment: MainAxisAlignment.start,
controller: _searchController, children: [
), InputField(
SizedBox(height: Get.height * 0.035), hintText: "Search Order",
Card( labelText: "Search Order",
margin: const EdgeInsets.symmetric(horizontal: 18), controller: _searchController,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(19),
side: const BorderSide(color: Color(0xFFFDFDFD)),
), ),
color: const Color(0xFFB4D1E5).withOpacity(0.9), SizedBox(height: Get.height * 0.035),
child: Padding( Card(
padding: const EdgeInsets.all(12.0), margin: const EdgeInsets.symmetric(horizontal: 18),
child: Column( shape: RoundedRectangleBorder(
mainAxisSize: MainAxisSize.min, borderRadius: BorderRadius.circular(19),
children: [ side: const BorderSide(color: Color(0xFFFDFDFD)),
SizedBox( ),
height: Get.height * 0.05, color: const Color(0xFFB4D1E5).withOpacity(0.9),
child: ListView.builder( child: Padding(
shrinkWrap: true, padding: const EdgeInsets.all(12.0),
scrollDirection: Axis.horizontal, child: Column(
itemCount: _filterList.length, mainAxisSize: MainAxisSize.min,
itemBuilder: (context, index) => Padding( children: [
padding: SizedBox(
const EdgeInsets.symmetric(horizontal: 4), height: Get.height * 0.05,
child: Chip( child: ListView.builder(
label: Text( shrinkWrap: true,
_filterList[index], scrollDirection: Axis.horizontal,
style: GoogleFonts.roboto( itemCount: _filterList.length,
fontSize: 14, itemBuilder: (context, index) => Padding(
fontWeight: FontWeight.w500, padding: const EdgeInsets.symmetric(horizontal: 4),
child: Chip(
label: Text(
_filterList[index],
style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w500),
), ),
), ),
), ),
), ),
), ),
), SizedBox(
SizedBox( height: Get.height * 0.6,
height: Get.height * 0.6, child: Obx(() {
child: ListView.builder( // Use a set to keep track of unique order IDs
padding: EdgeInsets.zero, final Set<String> uniqueOrderIds = {};
shrinkWrap: true, final List<PlacedOrderList> uniqueOrders = [];
itemCount: 2,
itemBuilder: (context, index) => Padding( for (var order in _getPlacedOrderController.placedOrders) {
padding: if (uniqueOrderIds.add(order.id)) {
const EdgeInsets.symmetric(vertical: 8), uniqueOrders.add(order);
child: Card( }
child: Column( }
crossAxisAlignment:
CrossAxisAlignment.start, return ListView.builder(
children: [ padding: EdgeInsets.zero,
Padding( shrinkWrap: true,
padding: const EdgeInsets.fromLTRB( itemCount: uniqueOrders.length,
16, 8, 8, 0), itemBuilder: (context, index) {
child: Text( final order = uniqueOrders[index];
"Order ID: 123456",
style: GoogleFonts.roboto( // Combine product names into a single string
fontSize: 14, final productNames = order.orderItem
fontWeight: FontWeight.w400, .map((item) => capitalizeFirstLetter(item.name))
), .join(', ');
),
), return Padding(
Padding( padding: const EdgeInsets.symmetric(vertical: 8),
padding: const EdgeInsets.fromLTRB( child: Card(
16, 8, 8, 0), child: Column(
child: Text( crossAxisAlignment: CrossAxisAlignment.start,
"Product Name: XYZ", children: [
style: GoogleFonts.roboto( Padding(
fontSize: 14, padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
fontWeight: FontWeight.w400, child: Row(
), mainAxisAlignment: MainAxisAlignment.start,
), children: [
), Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)),
Padding( Text("${order.id}")
padding: const EdgeInsets.fromLTRB( ],
16, 8, 8, 0), ),
child: Text( ),
"Order Date: MM/DD/YYYY", Padding(
style: GoogleFonts.roboto( padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
fontSize: 14, child: Row(
fontWeight: FontWeight.w400, crossAxisAlignment: CrossAxisAlignment.start, // Aligns the Column to the top of the Text
), children: [
), Text(
), "Product Names: ",
Padding( style: GoogleFonts.roboto(
padding: const EdgeInsets.fromLTRB( fontSize: 14,
16, 8, 8, 8), fontWeight: FontWeight.bold,
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,
), ),
), Expanded(
style: ElevatedButton.styleFrom( child: Column(
foregroundColor: Colors.white, crossAxisAlignment: CrossAxisAlignment.start, // Aligns text to the right within the Column
backgroundColor: children: [
const Color(0xFF004791), const SizedBox(height: 4), // Adds a small space between the label and the product names
shape: RoundedRectangleBorder( for (int i = 0; i < productNames.split(",").length; i++)
borderRadius: Text(
BorderRadius.circular(10), '${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( Padding(
fontSize: 14, padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
fontWeight: FontWeight.w400, 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<OrderManagementScreen> {
); );
} }
} }
// 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<OrderManagementScreen> createState() => _OrderManagementScreenState();
// }
//
// class _OrderManagementScreenState extends State<OrderManagementScreen> {
// final _searchController = TextEditingController();
// final List<String> _filterList = ["Order Status", "Date Range"];
//
// final GetPlacedOrderController _getPlacedOrderController = Get.put(GetPlacedOrderController());
// final CartController _cartController = Get.put(CartController());
//
// @override
// void initState() {
// super.initState();
// getOrder1();
// }
//
// Future<void> 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)),
// ),
// ),
// )
// ],
// ),
// ),
// );
// },
// );
// }),
// )
// ],
// ),
// ),
// ),
// ],
// ),
// ),
// ),
// ),
// ],
// ),
// );
// }
// }
//

View File

@ -62,8 +62,10 @@ class _CartScreenState extends State<CartScreen> {
), ),
), ),
], ],
title: const Text( title: Center(
"Cart", child: const Text(
"Cart",
),
), ),
), ),
drawer: const MyDrawer(), drawer: const MyDrawer(),
@ -114,11 +116,12 @@ class _CartScreenState extends State<CartScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"Subtotal Price: ", "Subtotal ",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 15, fontSize: 15,
color: Colors.black, color: Colors.black,
fontWeight: FontWeight.bold
), ),
), ),
Text("${_cartController.subtotal.value}"), Text("${_cartController.subtotal.value}"),
@ -136,11 +139,13 @@ class _CartScreenState extends State<CartScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"gstTotal Price: ", "GST ",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 15, fontSize: 15,
color: Colors.black, color: Colors.black,
fontWeight: FontWeight.bold
), ),
), ),
Text("${_cartController.gstTotal.value}"), Text("${_cartController.gstTotal.value}"),
@ -153,11 +158,12 @@ class _CartScreenState extends State<CartScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"grandTotal Price:", "Total Amount ",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 15, fontSize: 15,
color: Colors.black, color: Colors.black,
fontWeight: FontWeight.bold
), ),
), ),
Text("${_cartController.grandTotal.value}"), Text("${_cartController.grandTotal.value}"),

View File

@ -169,8 +169,10 @@ class _ProductCatalogScreenState extends State<ProductCatalogScreen> {
), ),
), ),
], ],
title: const Text( title: Center(
"Product Catalogue", child: const Text(
"Product Catalogue",
),
), ),
), ),
drawer: const MyDrawer(), drawer: const MyDrawer(),
@ -216,7 +218,7 @@ class _ProductCatalogScreenState extends State<ProductCatalogScreen> {
mainAxisAlignment: MainAxisAlignment.spaceBetween, mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [ children: [
Text( Text(
"Filters", "Filter",
style: GoogleFonts.poppins( style: GoogleFonts.poppins(
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
fontSize: 16, fontSize: 16,
@ -225,7 +227,7 @@ class _ProductCatalogScreenState extends State<ProductCatalogScreen> {
TextButton( TextButton(
onPressed: _clearFilters, onPressed: _clearFilters,
child: Text( child: Text(
"Clear Filters", "Clear Filter",
style: GoogleFonts.poppins( style: GoogleFonts.poppins(
color: Colors.red, color: Colors.red,
fontSize: 14, fontSize: 14,

View File

@ -24,6 +24,10 @@ class ProductDetailScreen extends StatefulWidget {
class _ProductDetailScreenState extends State<ProductDetailScreen> { class _ProductDetailScreenState extends State<ProductDetailScreen> {
final CartController _cartController = Get.put(CartController()); final CartController _cartController = Get.put(CartController());
String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
@ -92,7 +96,7 @@ class _ProductDetailScreenState extends State<ProductDetailScreen> {
padding: const EdgeInsets.all(8.0), padding: const EdgeInsets.all(8.0),
child: Container( child: Container(
height: Get.height * 0.4, height: Get.height * 0.4,
width: Get.width * 0.7, width: Get.width * 0.8,
decoration: BoxDecoration( decoration: BoxDecoration(
border: Border.all( border: Border.all(
width: 4, width: 4,
@ -112,47 +116,70 @@ class _ProductDetailScreenState extends State<ProductDetailScreen> {
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text( child: Row(
widget.productModel!.name, mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: GoogleFonts.roboto( children: [
fontSize: 20, Text("Product Name ",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),),
fontWeight: FontWeight.w600, Text(
color: Colors.white, capitalizeFirstLetter(widget.productModel!.name),
), style: GoogleFonts.roboto(
fontSize: 16,
// fontWeight: FontWeight.w600,
color: Colors.black,
),
),
],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text( child: Row(
"${widget.productModel!.price.toString()}", mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: GoogleFonts.roboto( children: [
fontSize: 24, Text("Price ",style: TextStyle(fontSize: 16,fontWeight: FontWeight.bold),),
fontWeight: FontWeight.w800, Text(
color: Colors.white, "${widget.productModel!.price.toString()}",
), style: GoogleFonts.roboto(
fontSize: 16,
//fontWeight: FontWeight.w800,
color: Colors.black,
),
),
],
), ),
), ),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text( child: Row(
widget.productModel!.category!.categoryName, mainAxisAlignment: MainAxisAlignment.spaceBetween,
style: GoogleFonts.roboto( children: [
fontSize: 16, Text("Category ",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16),),
fontWeight: FontWeight.w400, Text(
color: Colors.white, capitalizeFirstLetter(widget.productModel!.category!.categoryName),
), style: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
],
), ),
), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Padding( Padding(
padding: const EdgeInsets.symmetric(horizontal: 8), padding: const EdgeInsets.symmetric(horizontal: 8),
child: Text( child: Row(
widget.productModel!.description, children: [
style: GoogleFonts.roboto( Text("Description",style: TextStyle(fontWeight: FontWeight.bold,fontSize: 16)),
fontSize: 16, Text(
fontWeight: FontWeight.w400, capitalizeFirstLetter(widget.productModel!.description),
color: Colors.white, style: GoogleFonts.roboto(
), fontSize: 16,
fontWeight: FontWeight.w400,
color: Colors.black,
),
),
],
), ),
), ),
], ],
@ -167,7 +194,7 @@ class _ProductDetailScreenState extends State<ProductDetailScreen> {
onPressed: () { onPressed: () {
// Pass the product data to the CartScreen // Pass the product data to the CartScreen
_cartController.addToCart(widget.productModel!); _cartController.addToCart(widget.productModel!);
showSnackbar("Product Added to cart"); showSnackbar("Product successfully added to your cart");
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,

View File

@ -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";

View File

@ -1,5 +1,7 @@
import 'package:cheminova/controller/cart_controller.dart'; import 'package:cheminova/controller/cart_controller.dart';
import 'package:cheminova/models/oder_place_model.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/models/product_model.dart';
import 'package:cheminova/screens/product/product_detail_screen.dart'; import 'package:cheminova/screens/product/product_detail_screen.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
@ -13,17 +15,22 @@ import '../utils/show_snackbar.dart';
class ProductCard extends StatefulWidget { class ProductCard extends StatefulWidget {
final Product? productModel; final Product? productModel;
PlacedOrderModel? placedOrder; PlacedOrderModel? placedOrder;
PlacedOrderList? placedOrderList;
PlaceOrderItem1? placeorderItem;
ProductModel? product; ProductModel? product;
final bool isInCart; final bool isInCart;
final bool isCheckout; final bool isCheckout;
final bool isConfirmation; final bool isConfirmation;
int? quantity; int? quantity;
ProductCard({ ProductCard({
super.key, super.key,
this.product, this.product,
this.quantity=1, this.quantity = 1,
this.productModel, this.productModel,
this.placedOrder, this.placedOrder,
this.placedOrderList,
this.placeorderItem,
this.isInCart = false, this.isInCart = false,
this.isCheckout = false, this.isCheckout = false,
this.isConfirmation = false, this.isConfirmation = false,
@ -33,25 +40,26 @@ class ProductCard extends StatefulWidget {
State<ProductCard> createState() => _ProductCardState(); State<ProductCard> createState() => _ProductCardState();
} }
class _ProductCardState extends State<ProductCard> { class _ProductCardState extends State<ProductCard> {
@override String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase();
}
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
final CartController _cartController = Get.put(CartController()); final CartController _cartController = Get.put(CartController());
bool showQuantity = widget.isInCart || widget.isCheckout || widget.isConfirmation; 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 int currentQuantity = isProductInCart
? _cartController.cartList.firstWhere((p) => p.id == widget.productModel!.id).quantity ? _cartController.cartList.firstWhere((p) => p.id == widget.productModel!.id).quantity
: widget.productModel!.quantity; : widget.productModel!.quantity;
return GestureDetector( return GestureDetector(
onTap: () => widget.isInCart || widget.isCheckout onTap: () => widget.isInCart || widget.isCheckout
? null ? null
: Get.to(() => : Get.to(() => ProductDetailScreen(productModel: widget.productModel)),
ProductDetailScreen(productModel: widget.productModel)),
child: Card( child: Card(
child: Row( child: Row(
children: [ children: [
@ -65,7 +73,6 @@ class _ProductCardState extends State<ProductCard> {
decoration: BoxDecoration( decoration: BoxDecoration(
image: DecorationImage( image: DecorationImage(
image: AssetImage("assets/images/product.png"), image: AssetImage("assets/images/product.png"),
// Image.asset(productModel!['image']).image,
fit: BoxFit.cover, fit: BoxFit.cover,
), ),
), ),
@ -79,21 +86,21 @@ class _ProductCardState extends State<ProductCard> {
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Text( Text(
widget.productModel!.name, capitalizeFirstLetter(widget.productModel!.name),
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 16, fontSize: 16,
fontWeight: FontWeight.w500, fontWeight: FontWeight.w500,
), ),
), ),
Text( Text(
widget.productModel!.category!.categoryName, capitalizeFirstLetter(widget.productModel!.category!.categoryName),
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 14, fontSize: 14,
fontWeight: FontWeight.w400, fontWeight: FontWeight.w400,
), ),
), ),
Text( Text(
"${ widget.productModel!.price.toString()}", "${widget.productModel!.price.toString()}",
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: 22, fontSize: 22,
fontWeight: FontWeight.w700, fontWeight: FontWeight.w700,
@ -122,8 +129,7 @@ class _ProductCardState extends State<ProductCard> {
borderRadius: BorderRadius.circular(10), borderRadius: BorderRadius.circular(10),
), ),
child: Row( child: Row(
mainAxisAlignment: mainAxisAlignment: MainAxisAlignment.spaceAround,
MainAxisAlignment.spaceAround,
children: [ children: [
SizedBox( SizedBox(
height: 24, height: 24,
@ -132,20 +138,16 @@ class _ProductCardState extends State<ProductCard> {
onPressed: () { onPressed: () {
_cartController.decreaseQuantity(widget.productModel!); _cartController.decreaseQuantity(widget.productModel!);
setState(() { setState(() {
// Update the local quantity to reflect the change
currentQuantity = _cartController currentQuantity = _cartController
.cartList .cartList
.firstWhere((p) => .firstWhere((p) => p.id == widget.productModel!.id)
p.id ==
widget.productModel!.id)
.quantity; .quantity;
}); });
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: borderRadius: BorderRadius.circular(8.0),
BorderRadius.circular(8.0),
), ),
), ),
child: Text( child: Text(
@ -158,7 +160,7 @@ class _ProductCardState extends State<ProductCard> {
), ),
), ),
Text( Text(
"${currentQuantity}", "${currentQuantity}",
style: const TextStyle( style: const TextStyle(
color: Colors.white, color: Colors.white,
fontSize: 16, fontSize: 16,
@ -171,20 +173,16 @@ class _ProductCardState extends State<ProductCard> {
onPressed: () { onPressed: () {
_cartController.increaseQuantity(widget.productModel!); _cartController.increaseQuantity(widget.productModel!);
setState(() { setState(() {
// Update the local quantity to reflect the change
currentQuantity = _cartController currentQuantity = _cartController
.cartList .cartList
.firstWhere((p) => .firstWhere((p) => p.id == widget.productModel!.id)
p.id ==
widget.productModel!.id)
.quantity; .quantity;
}); });
}, },
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: borderRadius: BorderRadius.circular(8.0),
BorderRadius.circular(8.0),
), ),
), ),
child: Text( child: Text(
@ -199,13 +197,14 @@ class _ProductCardState extends State<ProductCard> {
], ],
), ),
), ),
SizedBox(width: 20.0,), SizedBox(
width: 20.0,
),
IconButton( IconButton(
onPressed: () { onPressed: () {
_cartController.removeFromCart(widget.productModel!); _cartController.removeFromCart(widget.productModel!);
showSnackbar("Product removed successfully!"); showSnackbar("Product has been removed successfully!");
setState(() { setState(() {
// Update the local quantity
currentQuantity = 1; currentQuantity = 1;
}); });
}, },
@ -222,14 +221,16 @@ class _ProductCardState extends State<ProductCard> {
showSnackbar("Product already added to cart"); showSnackbar("Product already added to cart");
} else { } else {
_cartController.addToCart(widget.productModel!); _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( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: const Color(0xFF00784C), backgroundColor: const Color(0xFF00784C),
padding: const EdgeInsets.symmetric( padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 8),
horizontal: 18, vertical: 8),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30), borderRadius: BorderRadius.circular(30),
), ),

View File

@ -176,6 +176,14 @@ packages:
url: "https://pub.dev" url: "https://pub.dev"
source: hosted source: hosted
version: "4.0.2" 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: leak_tracker:
dependency: transitive dependency: transitive
description: description:

View File

@ -43,6 +43,7 @@ dependencies:
shared_preferences: ^2.2.3 shared_preferences: ^2.2.3
logger: ^2.4.0 logger: ^2.4.0
get_storage: ^2.1.1 get_storage: ^2.1.1
intl: ^0.19.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test: