2025-12-03 11:57:05 +05:30
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
import '../providers/order_provider.dart';
|
|
|
|
|
import 'order_detail_screen.dart';
|
|
|
|
|
import 'order_invoice_screen.dart';
|
|
|
|
|
import 'order_track_screen.dart';
|
|
|
|
|
|
|
|
|
|
class OrdersScreen extends StatefulWidget {
|
|
|
|
|
const OrdersScreen({super.key});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<OrdersScreen> createState() => _OrdersScreenState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _OrdersScreenState extends State<OrdersScreen> {
|
2025-12-11 18:36:11 +05:30
|
|
|
String searchQuery = "";
|
2025-12-03 11:57:05 +05:30
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) {
|
|
|
|
|
Provider.of<OrderProvider>(context, listen: false).loadOrders();
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
final provider = Provider.of<OrderProvider>(context);
|
|
|
|
|
|
|
|
|
|
if (provider.loading) {
|
|
|
|
|
return const Center(child: CircularProgressIndicator());
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
final screenWidth = MediaQuery.of(context).size.width;
|
|
|
|
|
final scale = (screenWidth / 420).clamp(0.85, 1.15);
|
|
|
|
|
|
|
|
|
|
// FILTER ORDERS
|
|
|
|
|
final filteredOrders = provider.orders.where((o) {
|
|
|
|
|
final q = searchQuery.toLowerCase();
|
|
|
|
|
return o["order_id"].toString().toLowerCase().contains(q) ||
|
|
|
|
|
o["status"].toString().toLowerCase().contains(q) ||
|
|
|
|
|
o["description"].toString().toLowerCase().contains(q) ||
|
|
|
|
|
o["amount"].toString().toLowerCase().contains(q);
|
|
|
|
|
}).toList();
|
|
|
|
|
|
|
|
|
|
return Column(
|
|
|
|
|
children: [
|
|
|
|
|
// ⭐⭐ WHITE ELEVATED SEARCH BAR ⭐⭐
|
|
|
|
|
Container(
|
|
|
|
|
margin: EdgeInsets.fromLTRB(16 * scale, 16 * scale, 16 * scale, 10 * scale),
|
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 14 * scale),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
borderRadius: BorderRadius.circular(16 * scale),
|
|
|
|
|
boxShadow: [
|
|
|
|
|
BoxShadow(
|
|
|
|
|
color: Colors.black12.withOpacity(0.12),
|
|
|
|
|
blurRadius: 10 * scale,
|
|
|
|
|
spreadRadius: 1 * scale,
|
|
|
|
|
offset: Offset(0, 4 * scale),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(Icons.search,
|
|
|
|
|
size: 22 * scale, color: Colors.grey.shade700),
|
|
|
|
|
|
|
|
|
|
SizedBox(width: 10 * scale),
|
|
|
|
|
|
|
|
|
|
Expanded(
|
|
|
|
|
child: TextField(
|
|
|
|
|
onChanged: (value) => setState(() => searchQuery = value),
|
|
|
|
|
style: TextStyle(fontSize: 15 * scale),
|
|
|
|
|
decoration: InputDecoration(
|
|
|
|
|
hintText: "Search orders...",
|
|
|
|
|
hintStyle: TextStyle(
|
|
|
|
|
fontSize: 14 * scale,
|
|
|
|
|
color: Colors.grey.shade600,
|
|
|
|
|
),
|
|
|
|
|
border: InputBorder.none,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
// LIST OF ORDERS
|
|
|
|
|
Expanded(
|
|
|
|
|
child: ListView.builder(
|
|
|
|
|
padding: EdgeInsets.all(16 * scale),
|
|
|
|
|
itemCount: filteredOrders.length,
|
|
|
|
|
itemBuilder: (context, i) {
|
|
|
|
|
final order = filteredOrders[i];
|
|
|
|
|
return _orderCard(order, scale);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// ORDER CARD UI
|
|
|
|
|
Widget _orderCard(Map<String, dynamic> o, double scale) {
|
|
|
|
|
final progress = getProgress(o['status']);
|
|
|
|
|
final badgeColor = getStatusColor(o['status']);
|
|
|
|
|
|
|
|
|
|
return Card(
|
|
|
|
|
elevation: 3 * scale,
|
|
|
|
|
color: Colors.white,
|
|
|
|
|
margin: EdgeInsets.only(bottom: 16 * scale),
|
|
|
|
|
shape: RoundedRectangleBorder(
|
|
|
|
|
borderRadius: BorderRadius.circular(16 * scale),
|
|
|
|
|
),
|
|
|
|
|
child: Padding(
|
|
|
|
|
padding: EdgeInsets.all(16 * scale),
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: [
|
|
|
|
|
// TOP ROW
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
2025-12-03 11:57:05 +05:30
|
|
|
children: [
|
2025-12-11 18:36:11 +05:30
|
|
|
Text(
|
|
|
|
|
"Order #${o['order_id']}",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 18 * scale,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
Container(
|
|
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 12 * scale,
|
|
|
|
|
vertical: 6 * scale,
|
|
|
|
|
),
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: badgeColor.withOpacity(0.15),
|
|
|
|
|
borderRadius: BorderRadius.circular(12 * scale),
|
|
|
|
|
),
|
|
|
|
|
child: Text(
|
|
|
|
|
o['status'],
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: badgeColor,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
fontSize: 13 * scale,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
],
|
|
|
|
|
),
|
2025-12-11 18:36:11 +05:30
|
|
|
|
|
|
|
|
SizedBox(height: 10 * scale),
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
o['description'],
|
|
|
|
|
style: TextStyle(fontSize: 14 * scale),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 5 * scale),
|
|
|
|
|
|
|
|
|
|
Text(
|
|
|
|
|
"₹${o['amount']}",
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16 * scale,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 18 * scale),
|
|
|
|
|
|
|
|
|
|
_AnimatedProgressBar(progress: progress, scale: scale),
|
|
|
|
|
|
|
|
|
|
SizedBox(height: 18 * scale),
|
|
|
|
|
|
|
|
|
|
// BUTTONS
|
|
|
|
|
Row(
|
|
|
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
|
|
|
children: [
|
|
|
|
|
_btn(Icons.visibility, "View", Colors.green.shade800,
|
|
|
|
|
Colors.green.shade50, () => _openOrderDetails(o['order_id']), scale),
|
|
|
|
|
|
|
|
|
|
_btn(Icons.receipt_long, "Invoice", Colors.orange.shade800,
|
|
|
|
|
Colors.orange.shade50, () => _openInvoice(o['order_id']), scale),
|
|
|
|
|
|
|
|
|
|
_btn(Icons.local_shipping, "Track", Colors.blue.shade800,
|
|
|
|
|
Colors.blue.shade50, () => _openTrack(o['order_id']), scale),
|
|
|
|
|
],
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
// BUTTON UI
|
|
|
|
|
Widget _btn(IconData icon, String text, Color fg, Color bg,
|
|
|
|
|
VoidCallback onTap, double scale) {
|
2025-12-03 11:57:05 +05:30
|
|
|
return InkWell(
|
2025-12-11 18:36:11 +05:30
|
|
|
borderRadius: BorderRadius.circular(12 * scale),
|
2025-12-03 11:57:05 +05:30
|
|
|
onTap: onTap,
|
|
|
|
|
child: Container(
|
2025-12-11 18:36:11 +05:30
|
|
|
padding: EdgeInsets.symmetric(
|
|
|
|
|
horizontal: 20 * scale,
|
|
|
|
|
vertical: 12 * scale,
|
|
|
|
|
),
|
2025-12-03 11:57:05 +05:30
|
|
|
decoration: BoxDecoration(
|
2025-12-11 18:36:11 +05:30
|
|
|
color: bg,
|
|
|
|
|
borderRadius: BorderRadius.circular(12 * scale),
|
|
|
|
|
),
|
|
|
|
|
child: Row(
|
|
|
|
|
children: [
|
|
|
|
|
Icon(icon, size: 18 * scale, color: fg),
|
|
|
|
|
SizedBox(width: 8 * scale),
|
|
|
|
|
Text(
|
|
|
|
|
text,
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: fg,
|
|
|
|
|
fontWeight: FontWeight.w600,
|
|
|
|
|
fontSize: 14 * scale,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-12-03 11:57:05 +05:30
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
|
2025-12-11 18:36:11 +05:30
|
|
|
// NAVIGATION
|
2025-12-03 11:57:05 +05:30
|
|
|
void _openOrderDetails(String id) {
|
2025-12-11 18:36:11 +05:30
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (_) => OrderDetailScreen(orderId: id)),
|
|
|
|
|
);
|
2025-12-03 11:57:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _openInvoice(String id) {
|
2025-12-11 18:36:11 +05:30
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (_) => OrderInvoiceScreen(orderId: id)),
|
|
|
|
|
);
|
2025-12-03 11:57:05 +05:30
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void _openTrack(String id) {
|
2025-12-11 18:36:11 +05:30
|
|
|
Navigator.push(
|
|
|
|
|
context,
|
|
|
|
|
MaterialPageRoute(builder: (_) => OrderTrackScreen(orderId: id)),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// PROGRESS BAR
|
|
|
|
|
class _AnimatedProgressBar extends StatelessWidget {
|
|
|
|
|
final double progress;
|
|
|
|
|
final double scale;
|
|
|
|
|
|
|
|
|
|
const _AnimatedProgressBar({required this.progress, required this.scale});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return LayoutBuilder(
|
|
|
|
|
builder: (context, constraints) {
|
|
|
|
|
final maxW = constraints.maxWidth;
|
|
|
|
|
|
|
|
|
|
return Stack(
|
|
|
|
|
children: [
|
|
|
|
|
Container(
|
|
|
|
|
height: 10 * scale,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: Colors.grey.shade300,
|
|
|
|
|
borderRadius: BorderRadius.circular(20 * scale),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
AnimatedContainer(
|
|
|
|
|
duration: const Duration(milliseconds: 650),
|
|
|
|
|
curve: Curves.easeInOut,
|
|
|
|
|
height: 10 * scale,
|
|
|
|
|
width: maxW * progress,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(20 * scale),
|
|
|
|
|
gradient: const LinearGradient(
|
|
|
|
|
colors: [
|
|
|
|
|
Color(0xFF4F8CFF),
|
|
|
|
|
Color(0xFF8A4DFF),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
2025-12-03 11:57:05 +05:30
|
|
|
}
|
|
|
|
|
}
|
2025-12-11 18:36:11 +05:30
|
|
|
|
|
|
|
|
// PROGRESS VALUES
|
|
|
|
|
double getProgress(String? status) {
|
|
|
|
|
final s = (status ?? '').toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (s == "pending") return 0.25;
|
|
|
|
|
if (s == "loading") return 0.40;
|
|
|
|
|
if (s == "in transit" || s == "intransit") return 0.65;
|
|
|
|
|
if (s == "dispatched") return 0.85;
|
|
|
|
|
if (s == "delivered") return 1.0;
|
|
|
|
|
|
|
|
|
|
return 0.05;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// STATUS COLORS
|
|
|
|
|
Color getStatusColor(String? status) {
|
|
|
|
|
final s = (status ?? '').toLowerCase();
|
|
|
|
|
|
|
|
|
|
if (s == "pending") return Colors.orange;
|
|
|
|
|
if (s == "loading") return Colors.amber.shade800;
|
|
|
|
|
if (s == "in transit" || s == "intransit") return Colors.red;
|
|
|
|
|
if (s == "dispatched") return Colors.blue.shade700;
|
|
|
|
|
if (s == "delivered") return Colors.green.shade700;
|
|
|
|
|
|
|
|
|
|
return Colors.black54;
|
|
|
|
|
}
|