order_management UI and API Done

This commit is contained in:
Vaibhav 2024-10-07 13:16:43 +05:30
parent 7fc5702a9c
commit 6792c73cde
10 changed files with 450 additions and 351 deletions

View File

@ -1,17 +1,22 @@
import 'dart:developer';
import 'package:cheminova/controller/get_single_placed_order_service.dart'; import 'package:cheminova/controller/get_single_placed_order_service.dart';
import 'package:cheminova/controller/place_order_controller.dart'; import 'package:cheminova/controller/place_order_controller.dart';
import 'package:cheminova/models/place_order_list_model.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 'package:get/get.dart';
import '../models/oder_place_model.dart';
import '../models/product_model1.dart'; import '../models/product_model1.dart';
import '../utils/log_service.dart';
import 'get_place_order_service.dart'; import 'get_place_order_service.dart';
class GetPlacedOrderController extends GetxController { class GetPlacedOrderController extends GetxController {
final ApiService _apiService = ApiService();
final GetOrderPlacedService _getOrderPlacedService = GetOrderPlacedService(); final GetOrderPlacedService _getOrderPlacedService = GetOrderPlacedService();
final OrderPlacedController _orderPlacedController = Get.put(OrderPlacedController()); final OrderPlacedController _orderPlacedController =
final GetSingleOrderPlacedService _getSingleOrderPlacedService = GetSingleOrderPlacedService(); Get.put(OrderPlacedController());
final GetSingleOrderPlacedService _getSingleOrderPlacedService =
GetSingleOrderPlacedService();
var placedOrders = <PlacedOrderList>[].obs; var placedOrders = <PlacedOrderList>[].obs;
var products = <Product>[].obs; var products = <Product>[].obs;
@ -23,24 +28,47 @@ class GetPlacedOrderController extends GetxController {
getOrders(); // Fetch the orders immediately on initialization getOrders(); // Fetch the orders immediately on initialization
} }
RxInt currentPage = 1.obs;
RxBool hasMoreOrders = true.obs;
Future<void> getOrders() async { Future<void> getOrders() async {
if (isLoading.value || !hasMoreOrders.value) return;
final fetchedOrders = await _getOrderPlacedService.getPlacedOrders(); isLoading.value = true;
if (fetchedOrders != null && fetchedOrders.isNotEmpty) { try {
placedOrders.addAll(fetchedOrders); final response = await _apiService
//logger.w("Fetched orders: $fetchedOrders"); .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 { } 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<void> searchOrder() async { Future<void> searchOrder() async {
try { try {
isLoading.value = true; isLoading.value = true;
final order = await _getSingleOrderPlacedService.getSinglePlacedOrder(placedOrders[0].id); final order = await _getSingleOrderPlacedService
.getSinglePlacedOrder(placedOrders[0].sId ?? '');
if (order != null) { if (order != null) {
placedOrders.clear(); // Clear existing orders if needed placedOrders.clear(); // Clear existing orders if needed
placedOrders.add(order); placedOrders.add(order);
@ -54,10 +82,10 @@ class GetPlacedOrderController extends GetxController {
} }
} }
// Optional: Reset the pagination if needed // // Optional: Reset the pagination if needed
void resetPagination() { // void resetPagination() {
_getOrderPlacedService.resetPagination(); // _getOrderPlacedService.resetPagination();
placedOrders.clear(); // Clear existing data // placedOrders.clear(); // Clear existing data
getOrders(); // Fetch fresh data // getOrders(); // Fetch fresh data
} // }
} }

View File

@ -13,7 +13,7 @@ class GetOrderPlacedService {
try { try {
while (_hasMoreOrders) { while (_hasMoreOrders) {
// Construct the API URL with pagination parameters // 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<List<PlacedOrderList>>( final response = await commonApiService<List<PlacedOrderList>>(
method: "GET", method: "GET",

View File

@ -1,136 +1,188 @@
class PlacedOrderResponse {
List<PlacedOrderList>? placedOrders;
dynamic? totalOrders;
PlacedOrderResponse({this.placedOrders, this.totalOrders});
PlacedOrderResponse.fromJson(Map<dynamic, dynamic> json) {
if (json['placedOrders'] != null) {
placedOrders = <PlacedOrderList>[];
json['placedOrders'].forEach((v) {
placedOrders!.add(PlacedOrderList.fromJson(v));
});
}
totalOrders = json['totalOrders'];
}
Map<dynamic, dynamic> toJson() {
final Map<dynamic, dynamic> data = <dynamic, dynamic>{};
if (placedOrders != null) {
data['placedOrders'] = placedOrders!.map((v) => v.toJson()).toList();
}
data['totalOrders'] = totalOrders;
return data;
}
}
class PlacedOrderList { class PlacedOrderList {
final String id; dynamic? sId;
final String paymentMode; dynamic? paymentMode;
final String shipTo; dynamic? shipTo;
final String billTo; dynamic? billTo;
final List<OrderItem1> orderItem; List<OrderItem>? orderItem;
final double subtotal; dynamic? subtotal;
final double gstTotal; dynamic? gstTotal;
final double grandTotal; dynamic? grandTotal;
final String status; dynamic? status;
final String addedBy; List<dynamic>? invoices;
final bool isCancelled; dynamic? addedBy;
final bool isDelivered; dynamic? pd;
final String deliveredDate; bool? iscancelled;
final String uniqueId; bool? isDelivered;
final DateTime createdAt; dynamic? deliveredDate;
final DateTime updatedAt; dynamic? statusUpdatedAt;
dynamic? uniqueId;
dynamic? createdAt;
dynamic? updatedAt;
dynamic? iV;
PlacedOrderList({ PlacedOrderList(
required this.id, {this.sId,
required this.paymentMode, this.paymentMode,
required this.shipTo, this.shipTo,
required this.billTo, this.billTo,
required this.orderItem, this.orderItem,
required this.subtotal, this.subtotal,
required this.gstTotal, this.gstTotal,
required this.grandTotal, this.grandTotal,
required this.status, this.status,
required this.addedBy, this.invoices,
required this.isCancelled, this.addedBy,
required this.isDelivered, this.pd,
required this.deliveredDate, this.iscancelled,
required this.uniqueId, this.isDelivered,
required this.createdAt, this.deliveredDate,
required this.updatedAt, this.statusUpdatedAt,
}); this.uniqueId,
this.createdAt,
this.updatedAt,
this.iV});
factory PlacedOrderList.fromJson(Map<String, dynamic> json) { PlacedOrderList.fromJson(Map<dynamic, dynamic> json) {
return PlacedOrderList( sId = json['_id'];
id: json['_id'], paymentMode = json['paymentMode'];
paymentMode: json['paymentMode'], shipTo = json['shipTo'];
shipTo: json['shipTo'], billTo = json['billTo'];
billTo: json['billTo'], if (json['orderItem'] != null) {
orderItem: (json['orderItem'] as List) orderItem = <OrderItem>[];
.map((item) => OrderItem1.fromJson(item)) json['orderItem'].forEach((v) {
.toList(), orderItem!.add(OrderItem.fromJson(v));
subtotal: json['subtotal'].toDouble(), });
gstTotal: json['gstTotal'].toDouble(), }
grandTotal: json['grandTotal'].toDouble(), subtotal = json['subtotal'];
status: json['status'], gstTotal = json['gstTotal'];
addedBy: json['addedBy'], grandTotal = json['grandTotal'];
isCancelled: json['iscancelled'], status = json['status'];
isDelivered: json['isDelivered'], invoices = json['invoices'].cast<dynamic>();
deliveredDate: json['DeliveredDate'], addedBy = json['addedBy'];
uniqueId: json['uniqueId'], pd = json['pd'];
createdAt: DateTime.parse(json['createdAt']), iscancelled = json['iscancelled'];
updatedAt: DateTime.parse(json['updatedAt']), isDelivered = json['isDelivered'];
); deliveredDate = json['DeliveredDate'];
statusUpdatedAt = json['statusUpdatedAt'];
uniqueId = json['uniqueId'];
createdAt = json['createdAt'];
updatedAt = json['updatedAt'];
iV = json['__v'];
} }
Map<String, dynamic> toJson() { Map<dynamic, dynamic> toJson() {
return { final Map<dynamic, dynamic> data = <dynamic, dynamic>{};
'_id': id, data['_id'] = sId;
'paymentMode': paymentMode, data['paymentMode'] = paymentMode;
'shipTo': shipTo, data['shipTo'] = shipTo;
'billTo': billTo, data['billTo'] = billTo;
'orderItem': orderItem.map((item) => item.toJson()).toList(), if (orderItem != null) {
'subtotal': subtotal, data['orderItem'] = orderItem!.map((v) => v.toJson()).toList();
'gstTotal': gstTotal, }
'grandTotal': grandTotal, data['subtotal'] = subtotal;
'status': status, data['gstTotal'] = gstTotal;
'addedBy': addedBy, data['grandTotal'] = grandTotal;
'iscancelled': isCancelled, data['status'] = status;
'isDelivered': isDelivered, data['invoices'] = invoices;
'DeliveredDate': deliveredDate, data['addedBy'] = addedBy;
'uniqueId': uniqueId, data['pd'] = pd;
'createdAt': createdAt.toIso8601String(), data['iscancelled'] = iscancelled;
'updatedAt': updatedAt.toIso8601String(), data['isDelivered'] = isDelivered;
}; data['DeliveredDate'] = deliveredDate;
} data['statusUpdatedAt'] = statusUpdatedAt;
data['uniqueId'] = uniqueId;
@override data['createdAt'] = createdAt;
String toString() { data['updatedAt'] = updatedAt;
return 'PlacedOrderList(id: $id, paymentMode: $paymentMode, shipTo: $shipTo, billTo: $billTo, ' data['__v'] = iV;
'orderItem: $orderItem, subtotal: $subtotal, gstTotal: $gstTotal, grandTotal: $grandTotal, ' return data;
'status: $status, addedBy: $addedBy, isCancelled: $isCancelled, isDelivered: $isDelivered, '
'deliveredDate: $deliveredDate, uniqueId: $uniqueId, createdAt: $createdAt, updatedAt: $updatedAt)';
} }
} }
class OrderItem1 { class OrderItem {
final String sku; dynamic? productId;
final String name; dynamic? sKU;
final String categoryName; dynamic? name;
final String brandName; dynamic? categoryName;
final double price; dynamic? brandName;
final int quantity; dynamic? price;
dynamic? gST;
dynamic? hSNCode;
dynamic? description;
List<Null>? image;
dynamic? quantity;
dynamic? remainingQuantity;
dynamic? sId;
OrderItem1({ OrderItem(
required this.sku, {this.productId,
required this.name, this.sKU,
required this.categoryName, this.name,
required this.brandName, this.categoryName,
required this.price, this.brandName,
required this.quantity, this.price,
}); this.gST,
this.hSNCode,
this.description,
this.image,
this.quantity,
this.remainingQuantity,
this.sId});
factory OrderItem1.fromJson(Map<String, dynamic> json) { OrderItem.fromJson(Map<dynamic, dynamic> json) {
return OrderItem1( productId = json['productId'];
sku: json['SKU'], sKU = json['SKU'];
name: json['name'], name = json['name'];
categoryName: json['categoryName'], categoryName = json['categoryName'];
brandName: json['brandName'], brandName = json['brandName'];
price: json['price'].toDouble(), price = json['price'];
quantity: json['quantity'], gST = json['GST'];
); hSNCode = json['HSN_Code'];
description = json['description'];
quantity = json['quantity'];
remainingQuantity = json['remainingQuantity'];
sId = json['_id'];
} }
Map<String, dynamic> toJson() { Map<dynamic, dynamic> toJson() {
return { final Map<dynamic, dynamic> data = <dynamic, dynamic>{};
'SKU': sku, data['productId'] = productId;
'name': name, data['SKU'] = sKU;
'categoryName': categoryName, data['name'] = name;
'brandName': brandName, data['categoryName'] = categoryName;
'price': price, data['brandName'] = brandName;
'quantity': quantity, data['price'] = price;
}; data['GST'] = gST;
} data['HSN_Code'] = hSNCode;
data['description'] = description;
@override data['quantity'] = quantity;
String toString() { data['remainingQuantity'] = remainingQuantity;
return 'OrderItem(sku: $sku, name: $name, categoryName: $categoryName, ' data['_id'] = sId;
'brandName: $brandName, price: $price, quantity: $quantity)'; return data;
} }
} }

View File

@ -196,7 +196,7 @@ class _LoginScreenState extends State<LoginScreen> {
), ),
), ),
), ),
const SizedBox(height: 30), const SizedBox(height: 18),
// Login button with loading state // Login button with loading state
Obx( Obx(
() => CustomButton( () => CustomButton(

View File

@ -48,20 +48,20 @@ Future<void> adduni()async {
final List<PlacedOrderList> uniqueOrders = []; final List<PlacedOrderList> uniqueOrders = [];
for (var order in _getPlacedOrderController.placedOrders) { for (var order in _getPlacedOrderController.placedOrders) {
if (uniqueOrderIds.add(order.uniqueId)) { if (uniqueOrderIds.add(order.uniqueId??'')) {
uniqueOrders.add(order); uniqueOrders.add(order);
} }
} }
final order = uniqueOrders[0]; final order = uniqueOrders[0];
// Combine product names into a single string // Combine product names into a single string
final productNames = order.orderItem final productNames = order.orderItem!
.map((item) => (item.name)) .map((item) => (item.name))
.join(', '); .join(', ');
final categotyName = order.orderItem final categotyName = order.orderItem!
.map((item) => (item.categoryName)) .map((item) => (item.categoryName))
.join(', '); .join(', ');
final quantity = order.orderItem final quantity = order.orderItem!
.map((item) => (item.quantity)) .map((item) => (item.quantity))
.join(', '); .join(', ');
} }
@ -157,7 +157,7 @@ Future<void> adduni()async {
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,
), ),
), ),
Text(widget.placedOrderList!.uniqueId), Text(widget.placedOrderList!.uniqueId??''),
], ],
), ),
), ),
@ -212,9 +212,9 @@ Future<void> adduni()async {
padding: EdgeInsets.all(Get.width * 0.02), padding: EdgeInsets.all(Get.width * 0.02),
child: ListView.builder( child: ListView.builder(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
itemCount: widget.placedOrderList?.orderItem.length ?? 0, itemCount: widget.placedOrderList?.orderItem?.length ?? 0,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final orderItem = widget.placedOrderList!.orderItem[index]; final orderItem = widget.placedOrderList!.orderItem![index];
return orderItem != null return orderItem != null
? Card( ? Card(
margin: const EdgeInsets.symmetric(vertical: 5.0), margin: const EdgeInsets.symmetric(vertical: 5.0),
@ -237,7 +237,7 @@ Future<void> adduni()async {
crossAxisAlignment: CrossAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.end,
children: [ children: [
Text( Text(
capitalizeFirstLetter(orderItem.name), capitalizeFirstLetter(orderItem.name??''),
style: GoogleFonts.roboto( style: GoogleFonts.roboto(
fontSize: Get.width * 0.04, fontSize: Get.width * 0.04,
fontWeight: FontWeight.bold, fontWeight: FontWeight.bold,

View File

@ -59,218 +59,233 @@ class _OrderManagementScreenState extends State<OrderManagementScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Stack(
extendBodyBehindAppBar: true, children: [
appBar: AppBar( Scaffold(
centerTitle: true, extendBodyBehindAppBar: true,
backgroundColor: Colors.transparent, appBar: AppBar(
elevation: 0, centerTitle: true,
leading: Builder( backgroundColor: Colors.transparent,
builder: (context) { elevation: 0,
return GestureDetector( leading: Builder(
onTap: () => Scaffold.of(context).openDrawer(), builder: (context) {
child: Padding( return GestureDetector(
padding: const EdgeInsets.all(16.0), onTap: () => Scaffold.of(context).openDrawer(),
child: SvgPicture.asset('assets/svg/menu.svg'), 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'),
), ),
), actions: [
], GestureDetector(
title: const Text("Order Management"), onTap: () => Get.back(),
),
drawer: const MyDrawer(),
body: Stack(
fit: StackFit.expand,
children: [
Image.asset('assets/images/image_1.png', fit: BoxFit.cover),
SafeArea(
child: SingleChildScrollView(
child: Padding( child: Padding(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom), padding: const EdgeInsets.all(8.0),
child: RefreshIndicator( child: SvgPicture.asset('assets/svg/back_arrow.svg'),
key: _refreshIndicatorKey, ),
onRefresh: _onRefresh, ),
color: Colors.black, ],
backgroundColor: Colors.white, title: const Text("Order Management"),
child: Column( ),
mainAxisSize: MainAxisSize.min, drawer: const MyDrawer(),
mainAxisAlignment: MainAxisAlignment.start, body: Stack(
children: [ fit: StackFit.expand,
InputField( children: [
hintText: "Search Order", Image.asset('assets/images/image_1.png', fit: BoxFit.cover),
labelText: "Search Order", SafeArea(
controller: _searchController, child: SingleChildScrollView(
), child: Padding(
SizedBox(height: Get.height * 0.035), padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
Card( child: RefreshIndicator(
margin: const EdgeInsets.symmetric(horizontal: 18), key: _refreshIndicatorKey,
shape: RoundedRectangleBorder( onRefresh: _onRefresh,
borderRadius: BorderRadius.circular(19), color: Colors.black,
side: const BorderSide(color: Color(0xFFFDFDFD)), backgroundColor: Colors.white,
), child: Column(
color: const Color(0xFFB4D1E5).withOpacity(0.9), mainAxisSize: MainAxisSize.min,
child: Padding( mainAxisAlignment: MainAxisAlignment.start,
padding: const EdgeInsets.all(12.0), children: [
child: Column( InputField(
mainAxisSize: MainAxisSize.min, hintText: "Search Order",
children: [ labelText: "Search Order",
SizedBox( controller: _searchController,
height: Get.height * 0.05, ),
child: ListView.builder( SizedBox(height: Get.height * 0.035),
shrinkWrap: true, Card(
scrollDirection: Axis.horizontal, margin: const EdgeInsets.symmetric(horizontal: 18),
itemCount: _filterList.length, shape: RoundedRectangleBorder(
itemBuilder: (context, index) => Padding( borderRadius: BorderRadius.circular(19),
padding: const EdgeInsets.symmetric(horizontal: 4), side: const BorderSide(color: Color(0xFFFDFDFD)),
child: Chip( ),
label: Text( color: const Color(0xFFB4D1E5).withOpacity(0.9),
_filterList[index], child: Padding(
style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.w500), 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,
SizedBox( child: Obx(() {
height: Get.height * 0.6, // Use a set to keep track of unique order IDs
child: Obx(() { final Set<String> uniqueOrderIds = {};
// Use a set to keep track of unique order IDs final List<PlacedOrderList> uniqueOrders = [];
final Set<String> uniqueOrderIds = {};
final List<PlacedOrderList> uniqueOrders = [];
for (var order in _getPlacedOrderController.placedOrders) { for (var order in _getPlacedOrderController.placedOrders) {
if (uniqueOrderIds.add(order.id)) { if (uniqueOrderIds.add(order.sId??'')) {
uniqueOrders.add(order); uniqueOrders.add(order);
} }
} }
return ListView.builder( return ListView.builder(
padding: EdgeInsets.zero, padding: EdgeInsets.zero,
shrinkWrap: true, shrinkWrap: true,
itemCount: uniqueOrders.length, itemCount: uniqueOrders.length,
itemBuilder: (context, index) { itemBuilder: (context, index) {
final order = uniqueOrders[index]; final order = uniqueOrders[index];
// Combine product names into a single string // Combine product names into a single string
final productNames = order.orderItem final productNames = order.orderItem!
.map((item) => capitalizeFirstLetter(item.name)) .map((item) => capitalizeFirstLetter(item.name??''))
.join(', '); .join(', ');
return Padding( return Padding(
padding: const EdgeInsets.symmetric(vertical: 8), padding: const EdgeInsets.symmetric(vertical: 8),
child: Card( child: Card(
child: Column( child: Column(
crossAxisAlignment: CrossAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start,
children: [ children: [
Padding( Padding(
padding: const EdgeInsets.fromLTRB(16, 8, 8, 0), padding: const EdgeInsets.fromLTRB(16, 8, 8, 0),
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.start, mainAxisAlignment: MainAxisAlignment.start,
children: [ children: [
Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)), Text("Order ID: ", style: GoogleFonts.roboto(fontSize: 14, fontWeight: FontWeight.bold)),
Text("${order.uniqueId}") 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,
),
), ),
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();
},)
],
); );
} }
} }

View File

@ -23,10 +23,9 @@ class ApiService {
return e.response!; return e.response!;
} else { } else {
return Response( return Response(
requestOptions: RequestOptions(path: ''), requestOptions: RequestOptions(path: ''),
statusCode: 500, statusCode: 500,
data: {'message': 'An unexpected error occurred'}, data: {'message': 'An unexpected error occurred'});
);
} }
} }
} }

View File

@ -1,4 +1,5 @@
import 'package:dio/dio.dart'; import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:shared_preferences/shared_preferences.dart'; import 'package:shared_preferences/shared_preferences.dart';
class AuthInterceptor extends Interceptor { class AuthInterceptor extends Interceptor {
@ -9,6 +10,7 @@ class AuthInterceptor extends Interceptor {
final token = prefs.getString('token'); final token = prefs.getString('token');
if (token != null) { if (token != null) {
debugPrint('token-->\n $token\n');
options.headers['Authorization'] = 'Bearer $token'; options.headers['Authorization'] = 'Bearer $token';
} }

View File

@ -17,19 +17,22 @@ class CustomButton extends StatelessWidget {
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
width: double.infinity, width: double.infinity,
padding: const EdgeInsets.symmetric(vertical: 16, horizontal: 8), padding: EdgeInsets.symmetric(vertical:isLoading?0: 16, horizontal: 8),
child: ElevatedButton( child: ElevatedButton(
style: ElevatedButton.styleFrom( style: ElevatedButton.styleFrom(
foregroundColor: Colors.white, foregroundColor: Colors.white,
backgroundColor: const Color(0xFF004791), backgroundColor: const Color(0xFF004791),
padding: const EdgeInsets.symmetric(horizontal: 32, vertical: 16), padding: EdgeInsets.symmetric(horizontal: 32, vertical:isLoading?0: 16),
shape: RoundedRectangleBorder( shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(30), borderRadius: BorderRadius.circular(30),
), ),
), ),
onPressed: onPressed, onPressed: onPressed,
child: isLoading child: isLoading
? const CircularProgressIndicator() ? const CircularProgressIndicator(
strokeWidth: 1,color: Colors.white,
valueColor: AlwaysStoppedAnimation<Color>(Colors.blueGrey),
)
: Text( : Text(
text, text,
style: GoogleFonts.getFont( style: GoogleFonts.getFont(

View File

@ -32,7 +32,7 @@ class _MyDrawerState extends State<MyDrawer> {
return Center(child: Text(_homeController.error.value)); return Center(child: Text(_homeController.error.value));
} else { } else {
final user = _homeController.userProfile.value; final user = _homeController.userProfile.value;
return DrawerHeader( return user == null ?const SizedBox(): DrawerHeader(
decoration: const BoxDecoration( decoration: const BoxDecoration(
color: Colors.black87, color: Colors.black87,
), ),