From 6792c73cde44db58cf3404680ef8ba4311a83f61 Mon Sep 17 00:00:00 2001 From: Vaibhav Date: Mon, 7 Oct 2024 13:16:43 +0530 Subject: [PATCH] order_management UI and API Done --- .../get_order_placed_controller.dart | 62 ++- lib/controller/get_place_order_service.dart | 2 +- lib/models/place_order_list_model.dart | 296 +++++++------ lib/screens/authentication/login_screen.dart | 2 +- .../order_management_detail_screen.dart | 16 +- .../order_management_screen.dart | 403 +++++++++--------- lib/services/api_service.dart | 7 +- lib/services/app_interceptor.dart | 2 + lib/widgets/custom_button.dart | 9 +- lib/widgets/my_drawer.dart | 2 +- 10 files changed, 450 insertions(+), 351 deletions(-) diff --git a/lib/controller/get_order_placed_controller.dart b/lib/controller/get_order_placed_controller.dart index bed7dbc..911a9e7 100644 --- a/lib/controller/get_order_placed_controller.dart +++ b/lib/controller/get_order_placed_controller.dart @@ -1,17 +1,22 @@ +import 'dart:developer'; + 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/services/api_service.dart'; +import 'package:flutter/material.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 ApiService _apiService = ApiService(); final GetOrderPlacedService _getOrderPlacedService = GetOrderPlacedService(); - final OrderPlacedController _orderPlacedController = Get.put(OrderPlacedController()); - final GetSingleOrderPlacedService _getSingleOrderPlacedService = GetSingleOrderPlacedService(); + final OrderPlacedController _orderPlacedController = + Get.put(OrderPlacedController()); + final GetSingleOrderPlacedService _getSingleOrderPlacedService = + GetSingleOrderPlacedService(); var placedOrders = [].obs; var products = [].obs; @@ -23,24 +28,47 @@ class GetPlacedOrderController extends GetxController { getOrders(); // Fetch the orders immediately on initialization } + RxInt currentPage = 1.obs; + RxBool hasMoreOrders = true.obs; + Future getOrders() async { + if (isLoading.value || !hasMoreOrders.value) return; - final fetchedOrders = await _getOrderPlacedService.getPlacedOrders(); + isLoading.value = true; - if (fetchedOrders != null && fetchedOrders.isNotEmpty) { - placedOrders.addAll(fetchedOrders); - //logger.w("Fetched orders: $fetchedOrders"); + try { + final response = await _apiService + .get('/api/rd-place-order?page=${currentPage.value}'); + log('response ---- $response'); + PlacedOrderResponse data = PlacedOrderResponse.fromJson(response.data); + if (response.statusCode == 200) { + placedOrders.addAll(data.placedOrders ?? []); + debugPrint('allOrders.length: ${placedOrders.toJson()}'); + currentPage++; + hasMoreOrders.value = placedOrders.length < data.totalOrders!.toInt(); } else { - //logger.w("No orders fetched"); + throw Exception('Failed to load orders'); } - } + } catch (e) { + debugPrint('Error fetching orders: $e'); + } finally { + isLoading.value = false; + } + } + + void resetPagination() { + placedOrders.clear(); + currentPage.value = 1; + hasMoreOrders.value = true; + } Future searchOrder() async { try { isLoading.value = true; - final order = await _getSingleOrderPlacedService.getSinglePlacedOrder(placedOrders[0].id); + final order = await _getSingleOrderPlacedService + .getSinglePlacedOrder(placedOrders[0].sId ?? ''); if (order != null) { placedOrders.clear(); // Clear existing orders if needed placedOrders.add(order); @@ -54,10 +82,10 @@ class GetPlacedOrderController extends GetxController { } } - // Optional: Reset the pagination if needed - void resetPagination() { - _getOrderPlacedService.resetPagination(); - placedOrders.clear(); // Clear existing data - getOrders(); // Fetch fresh data - } +// // Optional: Reset the pagination if needed +// void resetPagination() { +// _getOrderPlacedService.resetPagination(); +// placedOrders.clear(); // Clear existing data +// getOrders(); // Fetch fresh data +// } } diff --git a/lib/controller/get_place_order_service.dart b/lib/controller/get_place_order_service.dart index ebab3fa..81ea68b 100644 --- a/lib/controller/get_place_order_service.dart +++ b/lib/controller/get_place_order_service.dart @@ -13,7 +13,7 @@ class GetOrderPlacedService { try { while (_hasMoreOrders) { // Construct the API URL with pagination parameters - String url = "api/rd-place-order?page=$_currentPage"; + String url = "/api/rd-place-order?page=$_currentPage"; final response = await commonApiService>( method: "GET", diff --git a/lib/models/place_order_list_model.dart b/lib/models/place_order_list_model.dart index 558900d..1c137c0 100644 --- a/lib/models/place_order_list_model.dart +++ b/lib/models/place_order_list_model.dart @@ -1,136 +1,188 @@ +class PlacedOrderResponse { + List? placedOrders; + dynamic? totalOrders; + + PlacedOrderResponse({this.placedOrders, this.totalOrders}); + + PlacedOrderResponse.fromJson(Map json) { + if (json['placedOrders'] != null) { + placedOrders = []; + json['placedOrders'].forEach((v) { + placedOrders!.add(PlacedOrderList.fromJson(v)); + }); + } + totalOrders = json['totalOrders']; + } + + Map toJson() { + final Map data = {}; + if (placedOrders != null) { + data['placedOrders'] = placedOrders!.map((v) => v.toJson()).toList(); + } + data['totalOrders'] = totalOrders; + return data; + } +} + class PlacedOrderList { - final String id; - final String paymentMode; - final String shipTo; - final String billTo; - final List orderItem; - final double subtotal; - final double gstTotal; - final double grandTotal; - final String status; - final String addedBy; - final bool isCancelled; - final bool isDelivered; - final String deliveredDate; - final String uniqueId; - final DateTime createdAt; - final DateTime updatedAt; + dynamic? sId; + dynamic? paymentMode; + dynamic? shipTo; + dynamic? billTo; + List? orderItem; + dynamic? subtotal; + dynamic? gstTotal; + dynamic? grandTotal; + dynamic? status; + List? invoices; + dynamic? addedBy; + dynamic? pd; + bool? iscancelled; + bool? isDelivered; + dynamic? deliveredDate; + dynamic? statusUpdatedAt; + dynamic? uniqueId; + dynamic? createdAt; + dynamic? updatedAt; + dynamic? iV; - 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, - }); + PlacedOrderList( + {this.sId, + this.paymentMode, + this.shipTo, + this.billTo, + this.orderItem, + this.subtotal, + this.gstTotal, + this.grandTotal, + this.status, + this.invoices, + this.addedBy, + this.pd, + this.iscancelled, + this.isDelivered, + this.deliveredDate, + this.statusUpdatedAt, + this.uniqueId, + this.createdAt, + this.updatedAt, + this.iV}); - factory PlacedOrderList.fromJson(Map json) { - return PlacedOrderList( - id: json['_id'], - paymentMode: json['paymentMode'], - shipTo: json['shipTo'], - billTo: json['billTo'], - orderItem: (json['orderItem'] as List) - .map((item) => OrderItem1.fromJson(item)) - .toList(), - subtotal: json['subtotal'].toDouble(), - gstTotal: json['gstTotal'].toDouble(), - grandTotal: json['grandTotal'].toDouble(), - status: json['status'], - addedBy: json['addedBy'], - isCancelled: json['iscancelled'], - isDelivered: json['isDelivered'], - deliveredDate: json['DeliveredDate'], - uniqueId: json['uniqueId'], - createdAt: DateTime.parse(json['createdAt']), - updatedAt: DateTime.parse(json['updatedAt']), - ); + PlacedOrderList.fromJson(Map json) { + sId = json['_id']; + paymentMode = json['paymentMode']; + shipTo = json['shipTo']; + billTo = json['billTo']; + if (json['orderItem'] != null) { + orderItem = []; + json['orderItem'].forEach((v) { + orderItem!.add(OrderItem.fromJson(v)); + }); + } + subtotal = json['subtotal']; + gstTotal = json['gstTotal']; + grandTotal = json['grandTotal']; + status = json['status']; + invoices = json['invoices'].cast(); + addedBy = json['addedBy']; + pd = json['pd']; + iscancelled = json['iscancelled']; + isDelivered = json['isDelivered']; + deliveredDate = json['DeliveredDate']; + statusUpdatedAt = json['statusUpdatedAt']; + uniqueId = json['uniqueId']; + createdAt = json['createdAt']; + updatedAt = json['updatedAt']; + iV = json['__v']; } - Map toJson() { - return { - '_id': id, - 'paymentMode': paymentMode, - 'shipTo': shipTo, - 'billTo': billTo, - 'orderItem': orderItem.map((item) => item.toJson()).toList(), - 'subtotal': subtotal, - 'gstTotal': gstTotal, - 'grandTotal': grandTotal, - 'status': status, - 'addedBy': addedBy, - 'iscancelled': isCancelled, - 'isDelivered': isDelivered, - 'DeliveredDate': deliveredDate, - 'uniqueId': uniqueId, - 'createdAt': createdAt.toIso8601String(), - 'updatedAt': updatedAt.toIso8601String(), - }; - } - - @override - String toString() { - return 'PlacedOrderList(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, ' - 'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, ' - 'status: $status, addedBy: $addedBy, isCancelled: $isCancelled, isDelivered: $isDelivered, ' - 'deliveredDate: $deliveredDate, uniqueId: $uniqueId, createdAt: $createdAt, updatedAt: $updatedAt)'; + Map toJson() { + final Map data = {}; + data['_id'] = sId; + data['paymentMode'] = paymentMode; + data['shipTo'] = shipTo; + data['billTo'] = billTo; + if (orderItem != null) { + data['orderItem'] = orderItem!.map((v) => v.toJson()).toList(); + } + data['subtotal'] = subtotal; + data['gstTotal'] = gstTotal; + data['grandTotal'] = grandTotal; + data['status'] = status; + data['invoices'] = invoices; + data['addedBy'] = addedBy; + data['pd'] = pd; + data['iscancelled'] = iscancelled; + data['isDelivered'] = isDelivered; + data['DeliveredDate'] = deliveredDate; + data['statusUpdatedAt'] = statusUpdatedAt; + data['uniqueId'] = uniqueId; + data['createdAt'] = createdAt; + data['updatedAt'] = updatedAt; + data['__v'] = iV; + return data; } } -class OrderItem1 { - final String sku; - final String name; - final String categoryName; - final String brandName; - final double price; - final int quantity; +class OrderItem { + dynamic? productId; + dynamic? sKU; + dynamic? name; + dynamic? categoryName; + dynamic? brandName; + dynamic? price; + dynamic? gST; + dynamic? hSNCode; + dynamic? description; + List? image; + dynamic? quantity; + dynamic? remainingQuantity; + dynamic? sId; - OrderItem1({ - required this.sku, - required this.name, - required this.categoryName, - required this.brandName, - required this.price, - required this.quantity, - }); + OrderItem( + {this.productId, + this.sKU, + this.name, + this.categoryName, + this.brandName, + this.price, + this.gST, + this.hSNCode, + this.description, + this.image, + this.quantity, + this.remainingQuantity, + this.sId}); - factory OrderItem1.fromJson(Map json) { - return OrderItem1( - sku: json['SKU'], - name: json['name'], - categoryName: json['categoryName'], - brandName: json['brandName'], - price: json['price'].toDouble(), - quantity: json['quantity'], - ); + OrderItem.fromJson(Map json) { + productId = json['productId']; + sKU = json['SKU']; + name = json['name']; + categoryName = json['categoryName']; + brandName = json['brandName']; + price = json['price']; + gST = json['GST']; + hSNCode = json['HSN_Code']; + description = json['description']; + quantity = json['quantity']; + remainingQuantity = json['remainingQuantity']; + sId = json['_id']; } - Map toJson() { - return { - 'SKU': sku, - 'name': name, - 'categoryName': categoryName, - 'brandName': brandName, - 'price': price, - 'quantity': quantity, - }; - } - - @override - String toString() { - return 'OrderItem(sku: $sku, name: $name, categoryName: $categoryName, ' - 'brandName: $brandName, price: $price, quantity: $quantity)'; + Map toJson() { + final Map data = {}; + data['productId'] = productId; + data['SKU'] = sKU; + data['name'] = name; + data['categoryName'] = categoryName; + data['brandName'] = brandName; + data['price'] = price; + data['GST'] = gST; + data['HSN_Code'] = hSNCode; + data['description'] = description; + data['quantity'] = quantity; + data['remainingQuantity'] = remainingQuantity; + data['_id'] = sId; + return data; } } - diff --git a/lib/screens/authentication/login_screen.dart b/lib/screens/authentication/login_screen.dart index cbbfe10..bab5143 100644 --- a/lib/screens/authentication/login_screen.dart +++ b/lib/screens/authentication/login_screen.dart @@ -196,7 +196,7 @@ class _LoginScreenState extends State { ), ), ), - const SizedBox(height: 30), + const SizedBox(height: 18), // Login button with loading state Obx( () => CustomButton( diff --git a/lib/screens/order_management/order_management_detail_screen.dart b/lib/screens/order_management/order_management_detail_screen.dart index c1729d7..77db590 100644 --- a/lib/screens/order_management/order_management_detail_screen.dart +++ b/lib/screens/order_management/order_management_detail_screen.dart @@ -48,20 +48,20 @@ Future adduni()async { final List uniqueOrders = []; for (var order in _getPlacedOrderController.placedOrders) { - if (uniqueOrderIds.add(order.uniqueId)) { + if (uniqueOrderIds.add(order.uniqueId??'')) { uniqueOrders.add(order); } } final order = uniqueOrders[0]; // Combine product names into a single string - final productNames = order.orderItem + final productNames = order.orderItem! .map((item) => (item.name)) .join(', '); - final categotyName = order.orderItem + final categotyName = order.orderItem! .map((item) => (item.categoryName)) .join(', '); - final quantity = order.orderItem + final quantity = order.orderItem! .map((item) => (item.quantity)) .join(', '); } @@ -157,7 +157,7 @@ Future adduni()async { fontWeight: FontWeight.bold, ), ), - Text(widget.placedOrderList!.uniqueId), + Text(widget.placedOrderList!.uniqueId??''), ], ), ), @@ -212,9 +212,9 @@ Future adduni()async { padding: EdgeInsets.all(Get.width * 0.02), child: ListView.builder( padding: EdgeInsets.zero, - itemCount: widget.placedOrderList?.orderItem.length ?? 0, + itemCount: widget.placedOrderList?.orderItem?.length ?? 0, itemBuilder: (context, index) { - final orderItem = widget.placedOrderList!.orderItem[index]; + final orderItem = widget.placedOrderList!.orderItem![index]; return orderItem != null ? Card( margin: const EdgeInsets.symmetric(vertical: 5.0), @@ -237,7 +237,7 @@ Future adduni()async { crossAxisAlignment: CrossAxisAlignment.end, children: [ Text( - capitalizeFirstLetter(orderItem.name), + capitalizeFirstLetter(orderItem.name??''), style: GoogleFonts.roboto( fontSize: Get.width * 0.04, fontWeight: FontWeight.bold, diff --git a/lib/screens/order_management/order_management_screen.dart b/lib/screens/order_management/order_management_screen.dart index d0fc0e7..56dbfc7 100644 --- a/lib/screens/order_management/order_management_screen.dart +++ b/lib/screens/order_management/order_management_screen.dart @@ -59,218 +59,233 @@ class _OrderManagementScreenState extends State { @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'), + return Stack( + children: [ + 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'), + ), + ); + }, ), - ), - ], - 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( + actions: [ + GestureDetector( + onTap: () => Get.back(), child: Padding( - padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), - child: RefreshIndicator( - key: _refreshIndicatorKey, - onRefresh: _onRefresh, - color: Colors.black, - backgroundColor: Colors.white, - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - InputField( - hintText: "Search Order", - labelText: "Search Order", - controller: _searchController, - ), - 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), + 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: RefreshIndicator( + key: _refreshIndicatorKey, + onRefresh: _onRefresh, + color: Colors.black, + backgroundColor: Colors.white, + child: Column( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + InputField( + hintText: "Search Order", + labelText: "Search Order", + controller: _searchController, + ), + 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(() { - // Use a set to keep track of unique order IDs - final Set uniqueOrderIds = {}; - final List uniqueOrders = []; + SizedBox( + height: Get.height * 0.6, + child: Obx(() { + // Use a set to keep track of unique order IDs + final Set uniqueOrderIds = {}; + final List uniqueOrders = []; - for (var order in _getPlacedOrderController.placedOrders) { - if (uniqueOrderIds.add(order.id)) { - uniqueOrders.add(order); - } - } + for (var order in _getPlacedOrderController.placedOrders) { + if (uniqueOrderIds.add(order.sId??'')) { + uniqueOrders.add(order); + } + } - return ListView.builder( - padding: EdgeInsets.zero, - shrinkWrap: true, - itemCount: uniqueOrders.length, - itemBuilder: (context, index) { - final order = uniqueOrders[index]; + return ListView.builder( + padding: EdgeInsets.zero, + shrinkWrap: true, + itemCount: uniqueOrders.length, + itemBuilder: (context, index) { + final order = uniqueOrders[index]; - // Combine product names into a single string - final productNames = order.orderItem - .map((item) => capitalizeFirstLetter(item.name)) - .join(', '); + // Combine product names into a single string + final productNames = order.orderItem! + .map((item) => capitalizeFirstLetter(item.name??'')) + .join(', '); - return Padding( - padding: const EdgeInsets.symmetric(vertical: 8), - child: Card( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), - Text("${order.uniqueId}") - ], - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), - child: Row( - crossAxisAlignment: CrossAxisAlignment.start, // Aligns the Column to the top of the Text - children: [ - Text( - "Product Names: ", - style: GoogleFonts.roboto( - fontSize: 14, - fontWeight: FontWeight.bold, - ), + return Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: Card( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text("${order.uniqueId}") + ], ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, // Aligns text to the right within the Column - children: [ - const SizedBox(height: 4), // Adds a small space between the label and the product names - for (int i = 0; i < productNames.split(",").length; i++) - Text( - '${i + 1}. ${productNames.split(",")[i].trim()}', // Adds index and trims whitespace - textAlign: TextAlign.left, // Aligns text to the right - style: GoogleFonts.roboto( - fontSize: 14, - ), - ), - ], - ), - ), - ], - ), - ), - - - Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text("Order Date: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), - Text(formatDate("${order.createdAt}")) - ], - ), - ), - Padding( - padding: const EdgeInsets.fromLTRB(16, 8, 8, 8), - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Text("Status: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), - Text(capitalizeFirstLetter("${order.status}")) - ], - ), - ), - SizedBox( - width: Get.width * 0.4, - child: Padding( - padding: const EdgeInsets.all(8.0), - child: ElevatedButton( - onPressed: () => Get.to(() => OrderManagementDetailScreen( - placedOrderList: uniqueOrders[index])), - style: ElevatedButton.styleFrom( - foregroundColor: Colors.white, - backgroundColor: const Color(0xFF004791), - shape: RoundedRectangleBorder( - borderRadius: BorderRadius.circular(10)), - ), - child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), ), - ), - ) - ], - ), - ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, // Aligns the Column to the top of the Text + children: [ + Text( + "Product Names: ", + style: GoogleFonts.roboto( + fontSize: 14, + fontWeight: FontWeight.bold, + ), + ), + Expanded( + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, // Aligns text to the right within the Column + children: [ + const SizedBox(height: 4), // Adds a small space between the label and the product names + for (int i = 0; i < productNames.split(",").length; i++) + Text( + '${i + 1}. ${productNames.split(",")[i].trim()}', // Adds index and trims whitespace + textAlign: TextAlign.left, // Aligns text to the right + style: GoogleFonts.roboto( + fontSize: 14, + ), + ), + ], + ), + ), + ], + ), + ), + + + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Order Date: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text(formatDate("${order.createdAt}")) + ], + ), + ), + Padding( + padding: const EdgeInsets.fromLTRB(16, 8, 8, 8), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Text("Status: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), + Text(capitalizeFirstLetter("${order.status}")) + ], + ), + ), + SizedBox( + width: Get.width * 0.4, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: ElevatedButton( + onPressed: () => Get.to(() => OrderManagementDetailScreen( + placedOrderList: uniqueOrders[index])), + style: ElevatedButton.styleFrom( + foregroundColor: Colors.white, + backgroundColor: const Color(0xFF004791), + shape: RoundedRectangleBorder( + borderRadius: BorderRadius.circular(10)), + ), + child: Text("View Details", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w400)), + ), + ), + ) + ], + ), + ), + ); + }, ); - }, - ); - }), - ) - ], + }), + ) + ], + ), + ), ), - ), + ], ), - ], + ), ), ), ), - ), + ], ), - ], - ), + ), + Obx(() { + if (_getPlacedOrderController.isLoading.value) { + return Container( + color: Colors.black.withOpacity(0.5), + child: const Center( + child: CircularProgressIndicator(strokeWidth: 1), + ), + ); + } + return const SizedBox.shrink(); + },) + ], ); } } diff --git a/lib/services/api_service.dart b/lib/services/api_service.dart index c715702..f07c320 100644 --- a/lib/services/api_service.dart +++ b/lib/services/api_service.dart @@ -23,10 +23,9 @@ class ApiService { return e.response!; } else { return Response( - requestOptions: RequestOptions(path: ''), - statusCode: 500, - data: {'message': 'An unexpected error occurred'}, - ); + requestOptions: RequestOptions(path: ''), + statusCode: 500, + data: {'message': 'An unexpected error occurred'}); } } } diff --git a/lib/services/app_interceptor.dart b/lib/services/app_interceptor.dart index 5197dac..6fdb21a 100644 --- a/lib/services/app_interceptor.dart +++ b/lib/services/app_interceptor.dart @@ -1,4 +1,5 @@ import 'package:dio/dio.dart'; +import 'package:flutter/material.dart'; import 'package:shared_preferences/shared_preferences.dart'; class AuthInterceptor extends Interceptor { @@ -9,6 +10,7 @@ class AuthInterceptor extends Interceptor { final token = prefs.getString('token'); if (token != null) { + debugPrint('token-->\n $token\n'); options.headers['Authorization'] = 'Bearer $token'; } diff --git a/lib/widgets/custom_button.dart b/lib/widgets/custom_button.dart index 5b1bc95..c91d020 100644 --- a/lib/widgets/custom_button.dart +++ b/lib/widgets/custom_button.dart @@ -17,19 +17,22 @@ class CustomButton extends StatelessWidget { Widget build(BuildContext context) { return Container( width: double.infinity, - padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 8), + padding: EdgeInsets.symmetric(vertical:isLoading?0: 16, horizontal: 8), child: ElevatedButton( style: ElevatedButton.styleFrom( foregroundColor: Colors.white, backgroundColor: const Color(0xFF004791), - padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16), + padding: EdgeInsets.symmetric(horizontal: 32, vertical:isLoading?0: 16), shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(30), ), ), onPressed: onPressed, child: isLoading - ? const CircularProgressIndicator() + ? const CircularProgressIndicator( + strokeWidth: 1,color: Colors.white, + valueColor: AlwaysStoppedAnimation(Colors.blueGrey), + ) : Text( text, style: GoogleFonts.getFont( diff --git a/lib/widgets/my_drawer.dart b/lib/widgets/my_drawer.dart index e03de30..9279760 100644 --- a/lib/widgets/my_drawer.dart +++ b/lib/widgets/my_drawer.dart @@ -32,7 +32,7 @@ class _MyDrawerState extends State { return Center(child: Text(_homeController.error.value)); } else { final user = _homeController.userProfile.value; - return DrawerHeader( + return user == null ?const SizedBox(): DrawerHeader( decoration: const BoxDecoration( color: Colors.black87, ),