import 'package:flutter/material.dart'; import 'package:intl/intl.dart'; import 'package:medcify/components/button.dart'; import 'package:medcify/constants.dart'; import 'package:medcify/models/order_item.dart'; import 'package:medcify/navigation/navigation.dart'; class OrdersCard extends StatelessWidget { OrderItem item; int currentIndex; Function(OrderItem) acceptOrder; Function(OrderItem) cancelOrder; Function() fetchOrders; OrdersCard({required this.item, required this.currentIndex, required this.acceptOrder, required this.cancelOrder, required this.fetchOrders}); Widget statusWidget(){ String status = "Pending"; Color color = Colors.blue; Color lightColor = Colors.blue.shade50; if(currentIndex == 1){ status = "Completed"; color = Colors.amber; lightColor = Colors.amber.shade50; }else if(currentIndex == 2){ status = "Cancelled"; color = Colors.red; lightColor = Colors.red.shade50; } return Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(30), color: lightColor, ), padding: const EdgeInsets.symmetric(horizontal: 16,vertical: 6), child: Text(status,style: TextStyle(color: color,fontWeight: FontWeight.w500,fontSize: 12),), ); } @override Widget build(BuildContext context) { return GestureDetector( behavior: HitTestBehavior.opaque, onTap: () async{ final result = await Navigation.instance.navigate("/orderDetail",args: item); if(result != null){ fetchOrders(); } }, child: Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(8), color: Colors.white, border: Border.all(color: Colors.grey.shade200) ), margin: const EdgeInsets.only(bottom: 12), padding: const EdgeInsets.symmetric(horizontal: 16,vertical: 24), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text("ORDERID",style: TextStyle(color: Constants.secondaryTextColor,fontSize: 11, fontWeight: FontWeight.w500),), const SizedBox(height: 4,), Text("${item.id}",style: const TextStyle(color: Colors.black,fontSize: 12.5,),), ], ), ), const SizedBox(width: 16,), Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text("TOTAL AMOUNT",style: TextStyle(color: Constants.secondaryTextColor,fontSize: 11, fontWeight: FontWeight.w500),), const SizedBox(height: 4,), Text("\u{20B9}${item.total}",style: const TextStyle(color: Colors.black,fontSize: 12.5,),), ], ), ), ], ), const SizedBox(height: 24,), const Text("DATE",style: TextStyle(color: Constants.secondaryTextColor,fontSize: 11, fontWeight: FontWeight.w500),), const SizedBox(height: 4,), Text(DateFormat().format(DateTime.parse(item.date ?? "")),style: const TextStyle(color: Colors.black,fontSize: 12.5,),), const SizedBox(height: 24,), Row( children: [ Expanded( child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ const Text("ORDERED BY",style: TextStyle(color: Constants.secondaryTextColor,fontSize: 11, fontWeight: FontWeight.w500),), const SizedBox(height: 4,), Text(item.user?.name ?? "",style: const TextStyle(color: Colors.black,fontSize: 12.5,),), ], ), ), const SizedBox(width: 16,), statusWidget(), ], ), Visibility( visible: currentIndex == 0, child: Container( margin: const EdgeInsets.only(top: 20), height: 36, child: ((item.amount == 0 || item.amount == null) && (item.prescription?.value ?? "").isNotEmpty) ? Button( color: Colors.red, text: "Cancel", onPressed: (){ cancelOrder(item); }, ) : Row( children: [ Expanded( child: Button( color: Colors.red, text: "Cancel", onPressed: (){ cancelOrder(item); }, ), ), const SizedBox(width: 16,), Expanded( child: Button( color: Colors.green, text: "Accept", onPressed: (){ acceptOrder(item); }, ), ), ], ), ), ) ], ), ), ); } }