diff --git a/lib/common/settings.dart b/lib/common/settings.dart index b46aa58..9725b67 100644 --- a/lib/common/settings.dart +++ b/lib/common/settings.dart @@ -139,6 +139,8 @@ class AppSettings{ static String verifyPhnUrl = host + 'phone'; static String uploadPicUrl = host + 'uploads-user'; static String getOrderRequestsFromUsersUrl = host + 'getuserRequestbookingsforsupplier'; + static String acceptOrderRequestsUrl = host + 'request-booking-with-charges'; + static String formDouble(dynamic s) { var comma = NumberFormat('#,##,###.##', 'en_IN'); @@ -223,6 +225,13 @@ class AppSettings{ return _headers; } + //request headers without content type + static Future> buildPutRequestHeaders() async { + Map _headers = new Map(); + _headers['Authorization'] = accessToken; + return _headers; + } + /*Apis Starts here*/ static Future login(payload) async { @@ -380,6 +389,30 @@ class AppSettings{ } } + static Future acceptOrderRequests(payload,dbId) async { + + var uri = Uri.parse(acceptOrderRequestsUrl+'/'+dbId+'/supplier/quote'); + + var response = await http.post(uri, body: json.encode(payload), headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return true; + } else if (response.statusCode == 401) { + bool status = await AppSettings.resetToken(); + if (status) { + response = await http.post(uri,body: json.encode(payload), headers: await buildRequestHeaders()); + if (response.statusCode == 200) { + return true; + } else { + return false; + } + } else { + return false; + } + } else { + return false; + } + } + /*Apis ends here*/ diff --git a/lib/orders/accept_order_requests.dart b/lib/orders/accept_order_requests.dart index 9136896..34934ab 100644 --- a/lib/orders/accept_order_requests.dart +++ b/lib/orders/accept_order_requests.dart @@ -5,28 +5,27 @@ import 'package:supplier_new/orders/edit_order_requests.dart'; class AcceptOrderRequests extends StatefulWidget { var order; var status; - AcceptOrderRequests({this.order,this.status}); + AcceptOrderRequests({this.order, this.status}); @override State createState() => _AcceptOrderRequestsState(); } class _AcceptOrderRequestsState extends State { - double advancePayable=0.0; - double advance=0.0; - double amountToPayAfterDelivery=0.0; - double totalFare=0.0; + int advancePayable = 0; + int advance =0; + double amountToPayAfterDelivery = 0.0; + double totalFare = 0.0; @override void initState() { // TODO: implement initState super.initState(); - advance=150; + advance = 150; advancePayable = advance; - totalFare=advance+double.parse(widget.order.quoted_amount); + totalFare = advance + double.parse(widget.order.quoted_amount); amountToPayAfterDelivery = totalFare - advancePayable; } - @override Widget build(BuildContext context) { return Scaffold( @@ -65,14 +64,13 @@ class _AcceptOrderRequestsState extends State { }, child: Padding( padding: - const EdgeInsets.fromLTRB(8, 8, 8, 8), // Add padding if needed + const EdgeInsets.fromLTRB(8, 8, 8, 8), // Add padding if needed child: Image.asset( 'images/backbutton_appbar.png', // Replace with your image path fit: BoxFit.contain, color: Color(0XFFFFFFFF), height: 24, width: 24, - ), ), ), @@ -123,9 +121,10 @@ class _AcceptOrderRequestsState extends State { children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, - children: [ + children: [ Container( - padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4), + padding: const EdgeInsets.symmetric( + horizontal: 8, vertical: 4), decoration: BoxDecoration( color: Color(0XFFFFFFFF), borderRadius: BorderRadius.circular(4), @@ -134,26 +133,30 @@ class _AcceptOrderRequestsState extends State { width: 0.5, ), ), - child: Text( - widget.status.status, - style: fontTextStyle(12, widget.status.statusColor, FontWeight.w500) - ), + child: Text(widget.status.status, + style: fontTextStyle( + 12, + widget.status.statusColor, + FontWeight.w500)), ), Text( widget.order.building_name, - style: fontTextStyle(20, const Color(0XFF2D2E30), FontWeight.w600), + style: fontTextStyle( + 20, const Color(0XFF2D2E30), FontWeight.w600), ), SizedBox(height: 4), Text( widget.order.displayAddress, - style: fontTextStyle(12, const Color(0XFF939495), FontWeight.w400), + style: fontTextStyle( + 12, const Color(0XFF939495), FontWeight.w400), ), ], ), const Spacer(), - Text( - widget.order.distanceInKm.toString()+'Km', - style: fontTextStyle(12, const Color(0XFF939495), FontWeight.w400), + Text( + widget.order.distanceInKm.toString() + 'Km', + style: fontTextStyle( + 12, const Color(0XFF939495), FontWeight.w400), ), ], ), @@ -161,93 +164,137 @@ class _AcceptOrderRequestsState extends State { ), ], ), - SizedBox(height:MediaQuery.of(context).size.height * .08,), + SizedBox( + height: MediaQuery.of(context).size.height * .08, + ), /// 🔹 Order Details Padding( - padding: EdgeInsets.fromLTRB(16,0,16,0), + padding: EdgeInsets.fromLTRB(16, 0, 16, 0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( + Text( "ORDER DETAILS", - style: fontTextStyle(10, const Color(0XFF2D2E30), FontWeight.w600), + style: fontTextStyle( + 10, const Color(0XFF2D2E30), FontWeight.w600), + ), + SizedBox( + height: MediaQuery.of(context).size.height * .011, ), - SizedBox(height:MediaQuery.of(context).size.height * .011,), _detailTwoRow( - "Tanker Price", "₹${AppSettings.formDouble(widget.order.quoted_amount) ?? ''}","images/financialsBottomIcon.png", - "", "","" + "Tanker Price", + "₹${AppSettings.formDouble(widget.order.quoted_amount) ?? ''}", + "images/financialsBottomIcon.png", + "", + "", + ""), + SizedBox( + height: MediaQuery.of(context).size.height * .02, ), - SizedBox(height:MediaQuery.of(context).size.height * .02,), _detailTwoRow( - "Water Type", "${widget.order.type_of_water}","images/water.png", - "Date of Delivery", "${widget.order.time}","images/calendar_appbar.png", + "Water Type", + "${widget.order.type_of_water}", + "images/water.png", + "Date of Delivery", + "${widget.order.time}", + "images/calendar_appbar.png", + ), + SizedBox( + height: MediaQuery.of(context).size.height * .02, ), - SizedBox(height:MediaQuery.of(context).size.height * .02,), _detailTwoRow( - "Capacity", "${widget.order.capacity}","images/capacity.png", - "Time of Delivery", "${widget.order.averageTime}","images/time.png", + "Capacity", + "${widget.order.capacity}", + "images/capacity.png", + "Time of Delivery", + "${widget.order.averageTime}", + "images/time.png", + ), + SizedBox( + height: MediaQuery.of(context).size.height * .02, ), - SizedBox(height:MediaQuery.of(context).size.height * .02,), _detailTwoRow( - "Quantity", "${widget.order.quantity}","images/quantity.png", - "Booking Charges", advance.toString(),"images/advance.png", + "Quantity", + "${widget.order.quantity}", + "images/quantity.png", + "Booking Charges", + advance.toString(), + "images/advance.png", ), - ], ), ), - SizedBox(height:MediaQuery.of(context).size.height * .008,), + SizedBox( + height: MediaQuery.of(context).size.height * .008, + ), + /// 🔹 Additional Details Padding( - padding: EdgeInsets.fromLTRB(16,0,16,16), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Text( - "ADDITIONAL DETAILS", - style: fontTextStyle(10, const Color(0XFF2D2E30), FontWeight.w600), - ), - SizedBox(height:MediaQuery.of(context).size.height * .011,), - Text( - "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " - "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " - "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " - "aliquip ex ea commodo consequat.", - style: fontTextStyle(12, const Color(0XFF646566), FontWeight.w400), - ), - ], - ) - - - ), + padding: EdgeInsets.fromLTRB(16, 0, 16, 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + "ADDITIONAL DETAILS", + style: fontTextStyle( + 10, const Color(0XFF2D2E30), FontWeight.w600), + ), + SizedBox( + height: MediaQuery.of(context).size.height * .011, + ), + Text( + "Lorem ipsum dolor sit amet, consectetur adipiscing elit, " + "sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. " + "Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut " + "aliquip ex ea commodo consequat.", + style: fontTextStyle( + 12, const Color(0XFF646566), FontWeight.w400), + ), + ], + )), /// 🔹 Payment Summary Padding( - padding: EdgeInsets.fromLTRB(16,0,16,16), + padding: EdgeInsets.fromLTRB(16, 0, 16, 16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text( + Text( "PAYMENT SUMMARY", - style: fontTextStyle(10, const Color(0XFF2D2E30), FontWeight.w600), + style: fontTextStyle( + 10, const Color(0XFF2D2E30), FontWeight.w600), ), - SizedBox(height:MediaQuery.of(context).size.height * .011,), - _detailRow("Tanker Price", "₹${AppSettings.formDouble(widget.order.quoted_amount) ?? ''}"), - SizedBox(height:MediaQuery.of(context).size.height * .004,), - _detailRow("Booking Charges", "₹ "+advance.toString()), - SizedBox(height:MediaQuery.of(context).size.height * .004,), - _detailRow("Total Amount", "₹ "+totalFare.toString()), - SizedBox(height:MediaQuery.of(context).size.height * .004,), - Divider(color: Color(0XFF646566), - thickness: 0.3,), - SizedBox(height:MediaQuery.of(context).size.height * .004,), - _detailRow("Booking Charges Payable",'₹${AppSettings.formDouble(advancePayable.toString()) ?? ''}' - - ), - SizedBox(height:MediaQuery.of(context).size.height * .004,), - _detailRow("Amount to Pay (After Delivery)", '₹${AppSettings.formDouble(amountToPayAfterDelivery.toString()) ?? ''}' - ), + SizedBox( + height: MediaQuery.of(context).size.height * .011, + ), + _detailRow("Tanker Price", + "₹${AppSettings.formDouble(widget.order.quoted_amount) ?? ''}"), + SizedBox( + height: MediaQuery.of(context).size.height * .004, + ), + _detailRow("Booking Charges", "₹ " + advance.toString()), + SizedBox( + height: MediaQuery.of(context).size.height * .004, + ), + _detailRow("Total Amount", "₹ " + totalFare.toString()), + SizedBox( + height: MediaQuery.of(context).size.height * .004, + ), + Divider( + color: Color(0XFF646566), + thickness: 0.3, + ), + SizedBox( + height: MediaQuery.of(context).size.height * .004, + ), + _detailRow("Booking Charges Payable", + '₹${AppSettings.formDouble(advancePayable.toString()) ?? ''}'), + SizedBox( + height: MediaQuery.of(context).size.height * .004, + ), + _detailRow("Amount to Pay (After Delivery)", + '₹${AppSettings.formDouble(amountToPayAfterDelivery.toString()) ?? ''}'), ], ), ), @@ -259,104 +306,164 @@ class _AcceptOrderRequestsState extends State { /// 🔹 Bottom Action Buttons bottomNavigationBar: Container( - padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), - decoration: BoxDecoration( - color: Color(0XFFFFFFFF), - border: Border(top: BorderSide(color: Color(0XFFF5F6F6))), - ), - child: Row( - children: [ - Expanded( - child: OutlinedButton( - style: OutlinedButton.styleFrom( - foregroundColor: Color(0XFF000000), - backgroundColor: Color(0xFFF1F1F1), - side: BorderSide(color: Color(0xFFF1F1F1)), - padding: EdgeInsets.symmetric(vertical: 10), // uniform height - ), - onPressed: () { - Navigator.push( - context, - MaterialPageRoute( - builder: (_) => EditOrderRequests( - order: widget.order, - advance: advance.toString(), - status: widget.status, + padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8), + decoration: BoxDecoration( + color: Color(0XFFFFFFFF), + border: Border(top: BorderSide(color: Color(0XFFF5F6F6))), + ), + child: Row( + children: [ + Expanded( + child: OutlinedButton( + style: OutlinedButton.styleFrom( + foregroundColor: Color(0XFF000000), + backgroundColor: Color(0xFFF1F1F1), + side: BorderSide(color: Color(0xFFF1F1F1)), + padding: + EdgeInsets.symmetric(vertical: 10), // uniform height + ), + onPressed: () { + Navigator.push( + context, + MaterialPageRoute( + builder: (_) => EditOrderRequests( + order: widget.order, + advance: advance.toString(), + status: widget.status, + ), ), - ), - ); - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset('images/edit.png', height: 20, width: 20), - SizedBox(width: 4), - Text( - "Edit Order", - style: fontTextStyle(14, const Color(0XFF000000), FontWeight.w400), - ), - ], + ); + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset('images/edit.png', height: 20, width: 20), + SizedBox(width: 4), + Text( + "Edit Order", + style: fontTextStyle( + 14, const Color(0XFF000000), FontWeight.w400), + ), + ], + ), ), ), - ), - - SizedBox(width: 8), - - Expanded( - child: OutlinedButton( - style: OutlinedButton.styleFrom( - foregroundColor: Color(0XFFE2483D), - backgroundColor: Colors.white, - side: BorderSide(color: Color(0XFFE2483D)), - padding: EdgeInsets.symmetric(vertical: 10), - ), - onPressed: () {}, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset('images/cross.png', height: 20, width: 20), - SizedBox(width: 4), - Text( - "Reject", - style: fontTextStyle(14, const Color(0XFF000000), FontWeight.w400), - ), - ], + SizedBox(width: 8), + Expanded( + child: OutlinedButton( + style: OutlinedButton.styleFrom( + foregroundColor: Color(0XFFE2483D), + backgroundColor: Colors.white, + side: BorderSide(color: Color(0XFFE2483D)), + padding: EdgeInsets.symmetric(vertical: 10), + ), + onPressed: ()async { + AppSettings.preLoaderDialog(context); + + bool isOnline = await AppSettings.internetConnectivity(); + + if (isOnline) { + var payload = new Map(); + payload["supplierId"] = AppSettings.supplierId; + payload["amount"] = int.parse(widget.order.quoted_amount); + payload["delivery_charges"] = advance; + payload["action"] = 'reject'; + + bool status = await AppSettings.acceptOrderRequests( + payload, widget.order.dbId); + + try { + if (status) { + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longSuccessToast("Order request rejected Successfully"); + Navigator.pop(context, true); + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast("reject of order request Failed"); + } + } catch (e) { + Navigator.of(context,rootNavigator: true).pop(); + print(e); + } + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast("Please Check internet"); + } + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset('images/cross.png', height: 20, width: 20), + SizedBox(width: 4), + Text( + "Reject", + style: fontTextStyle( + 14, const Color(0XFF000000), FontWeight.w400), + ), + ], + ), ), ), - ), - - SizedBox(width: 8), - - Expanded( - child: ElevatedButton( - style: ElevatedButton.styleFrom( - backgroundColor: Color(0XFF0A9E04), - foregroundColor: Color(0XFFFFFFFF), - padding: EdgeInsets.symmetric(vertical: 10), - ), - onPressed: () { - - - - }, - child: Row( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - Image.asset('images/rite.png', height: 20, width: 20), - SizedBox(width: 4), - Text( - "Accept", - style: fontTextStyle(14, const Color(0XFFFFFFFF), FontWeight.w400), - ), - ], + SizedBox(width: 8), + Expanded( + child: ElevatedButton( + style: ElevatedButton.styleFrom( + backgroundColor: Color(0XFF0A9E04), + foregroundColor: Color(0XFFFFFFFF), + padding: EdgeInsets.symmetric(vertical: 10), + ), + onPressed: () async { + AppSettings.preLoaderDialog(context); + + bool isOnline = await AppSettings.internetConnectivity(); + + if (isOnline) { + var payload = new Map(); + payload["supplierId"] = AppSettings.supplierId; + payload["amount"] = int.parse(widget.order.quoted_amount); + payload["delivery_charges"] = advance; + payload["action"] = 'accept'; + + bool status = await AppSettings.acceptOrderRequests( + payload, widget.order.dbId); + + try { + if (status) { + Navigator.of(context,rootNavigator: true).pop(); + Navigator.pop(context, true); + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast("Accept of order request Failed"); + } + } catch (e) { + Navigator.of(context,rootNavigator: true).pop(); + print(e); + } + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast("Please Check internet"); + } + }, + child: Row( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + Image.asset('images/rite.png', height: 20, width: 20), + SizedBox(width: 4), + Text( + "Accept", + style: fontTextStyle( + 14, const Color(0XFFFFFFFF), FontWeight.w400), + ), + ], + ), ), ), - ), - ], - ) - - - ), + ], + )), ); } @@ -367,24 +474,28 @@ class _AcceptOrderRequestsState extends State { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - Text(title, - style: fontTextStyle(12, const Color(0XFF646566), FontWeight.w400),), - Text(value, - style: fontTextStyle(12, const Color(0XFF2D2E30), FontWeight.w500),), + Text( + title, + style: fontTextStyle(12, const Color(0XFF646566), FontWeight.w400), + ), + Text( + value, + style: fontTextStyle(12, const Color(0XFF2D2E30), FontWeight.w500), + ), ], ), ); } Widget _detailTwoRow( - String title1, - String value1, - String path1, - String title2, - String value2, - String path2, { - EdgeInsetsGeometry padding = const EdgeInsets.symmetric(vertical: 6), - }) { + String title1, + String value1, + String path1, + String title2, + String value2, + String path2, { + EdgeInsetsGeometry padding = const EdgeInsets.symmetric(vertical: 6), + }) { final titleStyle = fontTextStyle(12, Color(0XFF646566), FontWeight.w400); final valueStyle = fontTextStyle(12, Color(0XFF343637), FontWeight.w500); @@ -408,8 +519,14 @@ class _AcceptOrderRequestsState extends State { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Text(t, style: titleStyle, maxLines: 1, overflow: TextOverflow.ellipsis), - Text(v, style: valueStyle, maxLines: 1, overflow: TextOverflow.ellipsis), + Text(t, + style: titleStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis), + Text(v, + style: valueStyle, + maxLines: 1, + overflow: TextOverflow.ellipsis), ], ), ) @@ -430,7 +547,4 @@ class _AcceptOrderRequestsState extends State { ), ); } - - - } diff --git a/lib/orders/edit_order_requests.dart b/lib/orders/edit_order_requests.dart index e8e2164..12b718a 100644 --- a/lib/orders/edit_order_requests.dart +++ b/lib/orders/edit_order_requests.dart @@ -212,8 +212,40 @@ class _EditOrderRequestsState extends State { borderRadius: BorderRadius.circular(24), // <-- radius here ), ), - onPressed: () { + onPressed: () async{ + AppSettings.preLoaderDialog(context); + + bool isOnline = await AppSettings.internetConnectivity(); + + if (isOnline) { + var payload = new Map(); + payload["supplierId"] = AppSettings.supplierId; + payload["amount"] = int.parse(widget.order.quoted_amount); + payload["delivery_charges"] = widget.advance; + payload["action"] = 'accept'; + + bool status = await AppSettings.acceptOrderRequests( + payload, widget.order.dbId); + try { + if (status) { + Navigator.of(context,rootNavigator: true).pop(); + Navigator.pop(context, true); + Navigator.pop(context, true); + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast("Accept of order request Failed"); + } + } catch (e) { + Navigator.of(context,rootNavigator: true).pop(); + print(e); + } + } + else{ + Navigator.of(context,rootNavigator: true).pop(); + AppSettings.longFailedToast("Please Check internet"); + } }, child: Row( mainAxisAlignment: MainAxisAlignment.center, diff --git a/lib/orders/order_requests.dart b/lib/orders/order_requests.dart index bdb71cd..5d0227a 100644 --- a/lib/orders/order_requests.dart +++ b/lib/orders/order_requests.dart @@ -43,11 +43,25 @@ class _OrderRequestsPageState extends State { } /// 🔹 Helper to get status based on order time - Map getOrderStatus(String orderTimeStr) { + Map getOrderStatus(String orderTimeStr, String dbStatus) { String status = "Invalid time"; Color color = Colors.grey; - if (orderTimeStr.isEmpty) return {"status": status, "color": color}; + final dbLower = (dbStatus ?? "").toLowerCase().trim(); + + // ✅ Statuses that ignore time + if (dbLower == "reject") return {"status": "Rejected", "color": const Color(0XFFE2483D)}; + if (dbLower == "accept") return {"status": "Accepted", "color": const Color(0XFF0A9E04)}; + if (dbLower == "delivered") return {"status": "Delivered", "color": const Color(0XFF2E7D32)}; + if (dbLower == "cancelled" || dbLower == "cancelled_by_user" || dbLower == "cancelled_by_supplier") { + return {"status": "Cancelled", "color": const Color(0XFF757575)}; + } + + // ✅ Time-based status (only if not rejected/accepted/etc.) + if (orderTimeStr.isEmpty) { + // fallback for pending without time + return {"status": "Pending", "color": const Color(0XFFE56910)}; + } try { final format = DateFormat("dd-MM-yyyy HH:mm"); @@ -55,29 +69,30 @@ class _OrderRequestsPageState extends State { final now = DateTime.now(); final difference = now.difference(orderTime); - if (difference.inHours < 2) { + if (difference.inMinutes < 2) { status = "New"; color = const Color(0XFF1D7AFC); // Blue - } else if (difference.inHours < 240) { - int remaining = 240 - difference.inHours; - status = "Expires in ${remaining}h"; - if (difference.inHours < 6) { - color = const Color(0XFFE56910); // Less urgent - } else { - color = const Color(0XFFE2483D); // More urgent - } - } - else { + } else if (difference.inMinutes < 30) { + final remaining = 30 - difference.inMinutes; + status = "Expires in ${remaining}m"; // show time for pending + color = difference.inMinutes < 10 + ? const Color(0XFFE56910) + : const Color(0XFFE2483D); + } else { + // Expired overrides pending status = "Expired"; - color = const Color(0XFF757575); // Grey + color = const Color(0XFF757575); } } catch (e) { debugPrint("⚠️ Error parsing time: $e"); + status = "Invalid time"; + color = Colors.grey; } return {"status": status, "color": color}; } + @override Widget build(BuildContext context) { return Scaffold( @@ -100,7 +115,7 @@ class _OrderRequestsPageState extends State { itemCount: orderRequestsList.length, itemBuilder: (context, index) { final order = orderRequestsList[index]; - final statusMap = getOrderStatus(order.time ?? ""); + final statusMap = getOrderStatus(order.time ?? "", order.status ?? ""); final status = statusMap['status']; final color = statusMap['color']; @@ -113,20 +128,26 @@ class _OrderRequestsPageState extends State { price: "₹${AppSettings.formDouble(order.quoted_amount) ?? ''}", ); - final isExpired = status.toLowerCase() == "expired"; + final noNavigateStatuses = ["expired", "rejected", "accepted", "delivered", "cancelled"]; + final disableNavigation = noNavigateStatuses.contains(status.toLowerCase()); final card = OrderCard(order: cardModel); - return isExpired - ? card + return disableNavigation + ? card // just show the card, no tap : GestureDetector( - onTap: () { - Navigator.push( + onTap: () async { + final result = await Navigator.push( context, MaterialPageRoute( - builder: (_) => AcceptOrderRequests(order: order,status:cardModel), + builder: (context) => AcceptOrderRequests(order: order, status: cardModel), ), ); + + // If result indicates API reload + if (result == true) { + _fetchOrders(); + } }, child: card, ); diff --git a/lib/orders/order_requests_model.dart b/lib/orders/order_requests_model.dart index ec8f328..f57878e 100644 --- a/lib/orders/order_requests_model.dart +++ b/lib/orders/order_requests_model.dart @@ -16,6 +16,8 @@ class OrderRequestsModel { double lng=0; double distanceInMeters=0; double distanceInKm=0.0; + String dbId = ''; + String status=''; OrderRequestsModel(); @@ -23,13 +25,18 @@ class OrderRequestsModel { OrderRequestsModel rtvm = new OrderRequestsModel(); rtvm.building_name = json['customer_details']['buildingName'] ?? ''; + rtvm.dbId = json['_id']?? ''; rtvm.address = json['customer_details']['profile']['address1'] ?? ''; rtvm.type_of_water = json['type_of_water'] ?? ''; rtvm.capacity = json['capacity'] ?? ''; rtvm.quantity = json['quantity']?? ''; rtvm.averageTime = json['time'] ?? ''; rtvm.time = json['my_supplier_entry']['time'] ?? ''; + rtvm.status = json['my_supplier_entry']['status'] ?? ''; rtvm.quoted_amount = json['my_supplier_entry']['quoted_amount'].toString() ?? ''; + rtvm.lng=json['customer_details']['longitude'] ?? 0.0; + rtvm.lat=json['customer_details']['latitude'] ?? 0.0; + // Split and trim List parts = rtvm.address.split(',').map((e) => e.trim()).toList(); @@ -37,13 +44,20 @@ class OrderRequestsModel { if (parts.length >= 2) { rtvm.displayAddress = parts[parts.length -4]; // "Banjara Hills" } - rtvm.distanceInMeters = double.parse((Geolocator.distanceBetween( + // Distance in meters + rtvm.distanceInMeters = double.parse( + Geolocator.distanceBetween( rtvm.lat, rtvm.lng, AppSettings.supplierLatitude, - AppSettings.supplierLongitude - ) / 1000).toStringAsFixed(2)); - rtvm.distanceInKm = double.parse(( rtvm.distanceInMeters / 1000).toStringAsFixed(1)); + AppSettings.supplierLongitude, + ).toStringAsFixed(2), + ); + +// Distance in km + rtvm.distanceInKm = double.parse( + (rtvm.distanceInMeters / 1000).toStringAsFixed(2), + ); return rtvm; }