Compare commits

..

No commits in common. "174d7afa99994929b1002a143e0d25337f023b2f" and "50b08287263195c48200ffce103d045ef04257a7" have entirely different histories.

19 changed files with 659 additions and 1324 deletions

View File

@ -1,63 +1,40 @@
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: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: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 GetOrderPlacedService _getOrderPlacedService = GetOrderPlacedService();
final OrderPlacedController _orderPlacedController = Get.put(OrderPlacedController());
final GetSingleOrderPlacedService _getSingleOrderPlacedService = GetSingleOrderPlacedService();
var placedOrders = <PlacedOrderList>[].obs;
var products = <Product>[].obs;
final GetOrderPlacedServcie _getOrderPlacedServcie = GetOrderPlacedServcie();
var products = <PlacedOrderModel>[].obs;
var isLoading = false.obs;
int _currentPage = 1;
bool isLoading = false;
@override
void onInit() {
super.onInit();
getOrders(); // Fetch the orders immediately on initialization
}
Future<void> 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<void> searchOrder() async {
Future<void> getOrder(String id) async {
if (isLoading) return;
isLoading = true;
try {
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
final fetchedProducts = await _getOrderPlacedServcie.getPlacedOrder();
if (fetchedProducts != null) {
products.addAll(fetchedProducts);
}
} catch (e) {
// Handle exceptions
print("Error fetching products: $e");
} finally {
isLoading.value = false;
isLoading = false;
update();
}
}
// Optional: Reset the pagination if needed
void resetPagination() {
_getOrderPlacedService.resetPagination();
placedOrders.clear(); // Clear existing data
getOrders(); // Fetch fresh data
}
}

View File

@ -1,122 +1,35 @@
import 'package:cheminova/models/place_order_list_model.dart';
import '../models/oder_place_model.dart';
import 'package:cheminova/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 = 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 {
class GetOrderPlacedServcie{
Future<List<PlacedOrderModel>?> getPlacedOrder() async {
try {
while (_hasMoreOrders) {
// Construct the API URL with pagination parameters
String url = "/api/get-placed-order-pd?page=$_currentPage";
String url;
final response = await commonApiService<List<PlacedOrderList>>(
url = "/api/get-placed-order-pd?id=66cc7869f02b935094127a27";
final response = await commonApiService<List<PlacedOrderModel>>(
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>))
final List<PlacedOrderModel> products = (json['plcaedOrders'] as List)
.map((productJson) => PlacedOrderModel.fromJson(productJson as Map<String, dynamic>))
.toList();
if (orders.isNotEmpty) {
_allOrders.addAll(orders);
_currentPage++;
// _limit += orders.length; // Adjust limit based on the number of fetched orders
return products;
} 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;
return response;
} 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<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

@ -1,30 +0,0 @@
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 {
//try {
// logger.w("orderjson ${jsonEncode(orderDetails.toJson())}");
logger.w("orderjson ${jsonEncode(orderDetails.toJson())}");
final response = await dio.post(
'https://api.cnapp.co.in/api/order-place', // Ensure this is your correct endpoint
'https://cheminova-api-2.onrender.com/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');

View File

@ -139,3 +139,45 @@ 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,51 +1,130 @@
class PlaceOrderItem1 {
final String sku;
String? id;
List<String>? 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<String, dynamic> 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<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)';
}
}
// 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<String> 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<String, dynamic> 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<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

@ -1,136 +0,0 @@
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

@ -25,8 +25,8 @@ class CheckoutScreen extends StatefulWidget {
final Product? productModel;
PlacedOrderModel? placeOrder;
List<Product>? selectedProducts;
CheckoutScreen({super.key, this.productModel, this.placeOrder,this.selectedProducts});
CheckoutScreen({super.key, this.productModel, this.placeOrder});
@override
State<CheckoutScreen> createState() => _CheckoutScreenState();
@ -157,7 +157,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
await _orderPlacedController.placeOrder();
if (_orderPlacedController.isLoading.value) {
showSnackbar("Order Placed Successfully");
showSnackbar("OderPlaced Successfully");
Get.to(() => OrderConfermationScreen(
placedOrder: _orderPlacedController.placedOrder1.value,
));
@ -292,7 +292,7 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
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<CheckoutScreen> {
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<CheckoutScreen> {
),
SizedBox(
child: RadioListTile(
title: const Text("Credit"),
title: const Text("credit"),
contentPadding: EdgeInsets.zero,
value: "credit",
groupValue: _groupValue,
@ -368,27 +368,12 @@ class _CheckoutScreenState extends State<CheckoutScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.subtotal.value.toStringAsFixed(2)}'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('GST',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'),
],
),
Text(
'Subtotal: \${_cartController.subtotal.value.toStringAsFixed(2)}'),
Text(
'GST: \${_cartController.gstTotal.value.toStringAsFixed(2)}'),
Text(
'Grand Total: \${_cartController.grandTotal.value.toStringAsFixed(2)}'),
],
),
),

View File

@ -38,11 +38,11 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
// ),
// ];
// void _getOrder(){
// final details = _getPlacedOrderController.getOrder();
// showSnackbar("Get Placed Order Sucessfully");
// print("dffgfg,$details");
// }
void _getOrder(){
final details = _getPlacedOrderController.getOrder(_cartController.cartList[0].id);
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<OrderConfermationScreen> {
'Order Summary',
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w500,
color: Colors.black,
),
),
@ -155,33 +155,17 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
Padding(
padding: EdgeInsets.all(Get.width * 0.02),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Subtotal',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.subtotal.value.toStringAsFixed(2)}'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('GST',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.gstTotal.value.toStringAsFixed(2)}'),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Total Amount',style: TextStyle(fontWeight: FontWeight.bold)),
Text('${_cartController.grandTotal.value.toStringAsFixed(2)}'),
],
),
Text(
'Subtotal: \${_cartController.subtotal.value.toStringAsFixed(2)}'),
Text(
'GST: \${_cartController.gstTotal.value.toStringAsFixed(2)}'),
Text(
'Grand Total: \${_cartController.grandTotal.value.toStringAsFixed(2)}'),
],
),
),
],
),
),
@ -205,22 +189,26 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
children: [
Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
controller: TextEditingController(
text: widget.placedOrder!.shipTo,
),
decoration: InputDecoration(
hintText: "Address : ${widget.placedOrder!.shipTo}",
hintStyle: GoogleFonts.roboto(
child: Text(
"Address :${widget.placedOrder!.shipTo}",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400,
),
border: OutlineInputBorder(),
),
),
// Padding(
// padding: const EdgeInsets.all(8.0),
// child: Text(
// "Contact: +91 9123456789",
// style: GoogleFonts.roboto(
// fontSize: Get.width * 0.04,
// fontWeight: FontWeight.w400,
// ),
// ),
// ),
],
),
]),
),
),
Card(
@ -230,7 +218,7 @@ class _OrderConfermationScreenState extends State<OrderConfermationScreen> {
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Text(
"Estimated Delivery Date: ${widget.placedOrder!.orderItems[0].createdAt}",
"Estimated Delivery Date: 20 Sep 2024",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400,
@ -244,7 +232,25 @@ 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,4 +1,3 @@
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';
@ -11,9 +10,8 @@ import '../../controller/cart_controller.dart';
import '../../models/product_model1.dart';
class OrderFullfilmentScreen extends StatefulWidget {
//final Product? productModel;
PlacedOrderList? placedOrderList;
OrderFullfilmentScreen({super.key,this.placedOrderList});
final Product? productModel;
const OrderFullfilmentScreen({super.key,required this.productModel});
@override
State<OrderFullfilmentScreen> createState() => _OrderFullfilmentScreenState();
@ -150,7 +148,7 @@ class _OrderFullfilmentScreenState extends State<OrderFullfilmentScreen> {
padding: EdgeInsets.zero,
itemCount: 10,
itemBuilder: (context, index) => ProductCard(
placedOrderList:widget.placedOrderList,
productModel:widget.productModel,
isCheckout: true,
),
),

View File

@ -1,7 +1,3 @@
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';
@ -10,16 +6,13 @@ 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;
PlacedOrderList? placedOrderList;
PlacedOrderModel? placedOrderModel;
OrderManagementDetailScreen({super.key,this.placedOrderList,this.placedOrderModel});
final Product? productModel;
const OrderManagementDetailScreen({super.key,required this.productModel});
@override
State<OrderManagementDetailScreen> createState() =>
@ -30,44 +23,16 @@ class OrderManagementDetailScreen extends StatefulWidget {
class _OrderManagementDetailScreenState
extends State<OrderManagementDetailScreen> {
final CartController _cartController = Get.put(CartController());
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<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(', ');
}
// final List<ProductModel> _checkoutList = [
// ProductModel(
// id: "1",
// image: 'assets/images/image_1.png',
// name: "Product 1",
// category: ProductCategory.food,
// description: 'Product 1 description',
// price: 100,
// ),
// ];
@override
Widget build(BuildContext context) {
return Scaffold(
@ -137,8 +102,8 @@ Future<void> adduni()async {
child: Text(
"Order Summary",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.05,
fontWeight: FontWeight.bold,
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w400,
),
),
),
@ -148,19 +113,13 @@ Future<void> adduni()async {
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Order ID:",
child: Text(
"Order ID: 123456",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w400,
),
),
Text(widget.placedOrderList!.id),
],
),
),
),
SizedBox(
@ -168,38 +127,26 @@ Future<void> adduni()async {
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Order Date: ",
child: Text(
"Order Date: MM/DD/YYYY",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w400,
),
),
Text(formatDate("${widget.placedOrderList!.createdAt}")),
],
),
),
),
SizedBox(
width: Get.width,
child: Padding(
padding: EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Total Amount: ",
padding: const EdgeInsets.all(8.0),
child: Text(
"Total Price: ₹ Total",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w400,
),
),
Text("${widget.placedOrderList!.grandTotal}"),
],
),
),
),
],
@ -213,52 +160,11 @@ Future<void> adduni()async {
padding: EdgeInsets.all(Get.width * 0.02),
child: ListView.builder(
padding: EdgeInsets.zero,
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),
itemCount: 10,
itemBuilder: (context, index) => ProductCard(
productModel: widget.productModel,
isCheckout: true,
),
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();
},
),
),
),
@ -286,33 +192,28 @@ Future<void> adduni()async {
child: Padding(
padding:
const EdgeInsets.fromLTRB(8, 8, 8, 0),
child: Row(
children: [
Text(
"Address: ",
child: Text(
"Address: Hyderabad",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold,
),
),
Text("${widget.placedOrderList!.shipTo}")
],
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,
),
),
),
),
// 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,
// ),
// ),
// ),
// ),
],
),
),
@ -322,18 +223,13 @@ Future<void> adduni()async {
width: Get.width,
child: Padding(
padding: const EdgeInsets.all(8),
child: Row(
children: [
Text(
"Status: ",
child: Text(
"Status: Processing/ Shipped/ Delivered",
style: GoogleFonts.roboto(
fontSize: Get.width * 0.04,
fontWeight: FontWeight.w600,
),
),
Text(capitalizeFirstLetter("${widget.placedOrderList!.status}")),
],
),
),
),
),
@ -342,31 +238,31 @@ Future<void> adduni()async {
),
),
SizedBox(height: Get.height * 0.04),
// 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,
// ),
// ),
// ),
// ),
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,
),
),
),
),
],
),
),

View File

@ -1,4 +1,3 @@
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';
@ -6,16 +5,12 @@ 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 {
final Product? productModel;
PlacedOrderList? placeOrder;
OrderManagementScreen({super.key, this.productModel, this.placeOrder});
Product? productModel;
OrderManagementScreen({super.key,this.productModel});
@override
State<OrderManagementScreen> createState() => _OrderManagementScreenState();
@ -23,39 +18,10 @@ class OrderManagementScreen extends StatefulWidget {
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());
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;
}
final List<String> _filterList = [
"Order Status",
"Date Range",
];
@override
Widget build(BuildContext context) {
@ -71,7 +37,9 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
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',
),
),
);
},
@ -81,26 +49,29 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
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: RefreshIndicator(
key: _refreshIndicatorKey,
onRefresh: _onRefresh,
color: Colors.black,
backgroundColor: Colors.white,
padding: EdgeInsets.only(
bottom: MediaQuery.of(context).viewInsets.bottom),
child: Column(
mainAxisSize: MainAxisSize.min,
mainAxisAlignment: MainAxisAlignment.start,
@ -130,11 +101,15 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
scrollDirection: Axis.horizontal,
itemCount: _filterList.length,
itemBuilder: (context, index) => Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
padding:
const EdgeInsets.symmetric(horizontal: 4),
child: Chip(
label: Text(
_filterList[index],
style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w500),
style: GoogleFonts.roboto(
fontSize: 14,
fontWeight: FontWeight.w500,
),
),
),
),
@ -142,96 +117,60 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
),
SizedBox(
height: Get.height * 0.6,
child: Obx(() {
// Use a set to keep track of unique order IDs
final Set<String> uniqueOrderIds = {};
final List<PlacedOrderList> uniqueOrders = [];
for (var order in _getPlacedOrderController.placedOrders) {
if (uniqueOrderIds.add(order.id)) {
uniqueOrders.add(order);
}
}
return ListView.builder(
child: 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),
itemCount: 2,
itemBuilder: (context, index) => Padding(
padding:
const EdgeInsets.symmetric(vertical: 8),
child: Card(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
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: ",
padding: const EdgeInsets.fromLTRB(
16, 8, 8, 0),
child: Text(
"Order ID: 123456",
style: GoogleFonts.roboto(
fontSize: 14,
fontWeight: FontWeight.bold,
fontWeight: FontWeight.w400,
),
),
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
),
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: 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}"))
],
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(
@ -239,25 +178,36 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
child: Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: () => Get.to(() => OrderManagementDetailScreen(
placedOrderList: uniqueOrders[index])),
onPressed: () => Get.to(
() =>
OrderManagementDetailScreen(
productModel:widget.productModel,
),
),
style: ElevatedButton.styleFrom(
foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791),
backgroundColor:
const Color(0xFF004791),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)),
borderRadius:
BorderRadius.circular(10),
),
),
child: Text(
"View Details",
style: GoogleFonts.roboto(
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)),
),
),
)
],
),
),
);
},
);
}),
),
),
)
],
),
@ -268,259 +218,8 @@ 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,12 +62,10 @@ class _CartScreenState extends State<CartScreen> {
),
),
],
title: Center(
child: const Text(
title: const Text(
"Cart",
),
),
),
drawer: const MyDrawer(),
body: Stack(
fit: StackFit.expand,
@ -112,20 +110,13 @@ class _CartScreenState extends State<CartScreen> {
height: 10,
),
Obx(() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Subtotal ",
return Text(
"Subtotal Price: ₹ ${_cartController.subtotal.value}",
style: GoogleFonts.roboto(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.bold
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
Text("${_cartController.subtotal.value}"),
],
);
}),
@ -135,39 +126,24 @@ class _CartScreenState extends State<CartScreen> {
// height: 16,
// ),
Obx(() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"GST ",
return Text(
"gstTotal Price: ₹ ${_cartController.gstTotal.value}",
style: GoogleFonts.roboto(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.bold
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
Text("${_cartController.gstTotal.value}"),
],
);
}),
Obx(() {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
"Total Amount ",
return Text(
"grandTotal Price: ₹ ${_cartController.grandTotal.value}",
style: GoogleFonts.roboto(
fontSize: 15,
color: Colors.black,
fontWeight: FontWeight.bold
fontWeight: FontWeight.w700,
color: Colors.white,
),
),
Text("${_cartController.grandTotal.value}"),
],
);
}),

View File

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

View File

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

View File

@ -1,3 +1 @@
//String baseUrl = "https://cheminova-api-2.onrender.com";
String baseUrl = "https://api.cnapp.co.in";
String baseUrl = "https://cheminova-api-2.onrender.com";

View File

@ -1,7 +1,5 @@
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';
@ -9,28 +7,23 @@ import 'package:get/get.dart';
import 'package:google_fonts/google_fonts.dart';
import '../models/product_model1.dart';
import '../screens/product/cart_screen.dart';
import '../utils/show_snackbar.dart';
class ProductCard extends StatefulWidget {
final Product? productModel;
PlacedOrderModel? placedOrder;
PlacedOrderList? placedOrderList;
PlaceOrderItem1? placeorderItem;
ProductModel? product;
final bool isInCart;
final bool isCheckout;
final bool isConfirmation;
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,
@ -40,26 +33,20 @@ class ProductCard extends StatefulWidget {
State<ProductCard> createState() => _ProductCardState();
}
class _ProductCardState extends State<ProductCard> {
String capitalizeFirstLetter(String text) {
if (text.isEmpty) return text;
return text[0].toUpperCase() + text.substring(1).toLowerCase();
}
@override
@override
Widget build(BuildContext context) {
final CartController _cartController = Get.put(CartController());
bool showQuantity = widget.isInCart || widget.isCheckout || widget.isConfirmation;
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;
bool isProductInCart = _cartController.cartList.contains(widget.productModel);
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: [
@ -73,6 +60,7 @@ class _ProductCardState extends State<ProductCard> {
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/product.png"),
// Image.asset(productModel!['image']).image,
fit: BoxFit.cover,
),
),
@ -86,21 +74,21 @@ class _ProductCardState extends State<ProductCard> {
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
capitalizeFirstLetter(widget.productModel!.name),
widget.productModel!.name,
style: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w500,
),
),
Text(
capitalizeFirstLetter(widget.productModel!.category!.categoryName),
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,
@ -108,7 +96,7 @@ class _ProductCardState extends State<ProductCard> {
),
showQuantity
? Text(
"Quantity: ${currentQuantity}",
"Quantity: ${widget.productModel!.quantity.toString()}",
style: GoogleFonts.roboto(
fontSize: 15,
fontWeight: FontWeight.w700,
@ -129,43 +117,9 @@ class _ProductCardState extends State<ProductCard> {
borderRadius: BorderRadius.circular(10),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
mainAxisAlignment:
MainAxisAlignment.spaceAround,
children: [
SizedBox(
height: 24,
width: 24,
child: ElevatedButton(
onPressed: () {
_cartController.decreaseQuantity(widget.productModel!);
setState(() {
currentQuantity = _cartController
.cartList
.firstWhere((p) => p.id == widget.productModel!.id)
.quantity;
});
},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
),
),
child: Text(
'-',
style: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w800,
),
),
),
),
Text(
"${currentQuantity}",
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
),
SizedBox(
height: 24,
width: 24,
@ -173,16 +127,15 @@ class _ProductCardState extends State<ProductCard> {
onPressed: () {
_cartController.increaseQuantity(widget.productModel!);
setState(() {
currentQuantity = _cartController
.cartList
.firstWhere((p) => p.id == widget.productModel!.id)
.quantity;
widget.quantity = widget.productModel!.quantity;
});
},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8.0),
borderRadius:
BorderRadius.circular(8.0),
),
),
child: Text(
@ -194,19 +147,47 @@ class _ProductCardState extends State<ProductCard> {
),
),
),
],
Text(
"${widget.quantity}",
style: const TextStyle(
color: Colors.white,
fontSize: 16,
),
),
SizedBox(
width: 20.0,
height: 24,
width: 24,
child: ElevatedButton(
onPressed: () {
_cartController.decreaseQuantity(widget.productModel!);
setState(() {
widget.quantity = widget.productModel!.quantity;
});
},
style: ElevatedButton.styleFrom(
padding: EdgeInsets.zero,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(8.0),
),
),
child: Text(
'-',
style: GoogleFonts.roboto(
fontSize: 16,
fontWeight: FontWeight.w800,
),
),
),
),
],
),
),
SizedBox(width: 20.0,),
IconButton(
onPressed: () {
_cartController.removeFromCart(widget.productModel!);
showSnackbar("Product has been removed successfully!");
setState(() {
currentQuantity = 1;
});
},
icon: const Icon(
Icons.delete_outline_rounded,
@ -221,16 +202,14 @@ class _ProductCardState extends State<ProductCard> {
showSnackbar("Product already added to cart");
} else {
_cartController.addToCart(widget.productModel!);
showSnackbar("Product successfully added to your cart");
// setState(() {
// currentQuantity = widget.productModel!.quantity;
// });
showSnackbar("Product added to cart successfully");
}
},
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),
),

View File

@ -144,14 +144,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "4.6.6"
get_storage:
dependency: "direct main"
description:
name: get_storage
sha256: "39db1fffe779d0c22b3a744376e86febe4ade43bf65e06eab5af707dc84185a2"
url: "https://pub.dev"
source: hosted
version: "2.1.1"
google_fonts:
dependency: "direct main"
description:
@ -176,14 +168,6 @@ 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:

View File

@ -42,8 +42,6 @@ dependencies:
http: ^1.2.2
shared_preferences: ^2.2.3
logger: ^2.4.0
get_storage: ^2.1.1
intl: ^0.19.0
dev_dependencies:
flutter_test: