Files
kent_logistics_app/lib/screens/order_screen.dart

369 lines
11 KiB
Dart
Raw Normal View History

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;
2025-12-25 10:26:47 +05:30
final scale = (screenWidth / 420).clamp(0.85, 1.1);
2025-12-11 18:36:11 +05:30
final filteredOrders = provider.orders.where((o) {
final q = searchQuery.toLowerCase();
return o["order_id"].toString().toLowerCase().contains(q) ||
o["status"].toString().toLowerCase().contains(q) ||
2025-12-25 10:26:47 +05:30
o["description"].toString().toLowerCase().contains(q);
2025-12-11 18:36:11 +05:30
}).toList();
return Column(
children: [
2025-12-25 10:26:47 +05:30
_searchBar(scale),
2025-12-11 18:36:11 +05:30
Expanded(
child: ListView.builder(
2025-12-25 10:26:47 +05:30
padding: EdgeInsets.all(14 * scale),
2025-12-11 18:36:11 +05:30
itemCount: filteredOrders.length,
itemBuilder: (context, i) {
2025-12-25 10:26:47 +05:30
return _orderCard(filteredOrders[i], scale);
2025-12-11 18:36:11 +05:30
},
),
),
],
);
}
2025-12-25 10:26:47 +05:30
Widget _searchBar(double scale) {
return Container(
margin: EdgeInsets.fromLTRB(14 * scale, 14 * scale, 14 * scale, 8 * scale),
padding: EdgeInsets.symmetric(horizontal: 12 * scale),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(14 * scale),
boxShadow: [
BoxShadow(
color: Colors.black12.withOpacity(0.1),
blurRadius: 8 * scale,
offset: const Offset(0, 3),
),
],
),
child: Row(
children: [
Icon(Icons.search, size: 20 * scale, color: Colors.grey.shade700),
SizedBox(width: 8 * scale),
Expanded(
child: TextField(
onChanged: (v) => setState(() => searchQuery = v),
decoration: const InputDecoration(
hintText: "Search orders...",
border: InputBorder.none,
),
),
),
],
),
);
}
2025-12-11 18:36:11 +05:30
Widget _orderCard(Map<String, dynamic> o, double scale) {
final progress = getProgress(o['status']);
2025-12-25 10:26:47 +05:30
final percent = (progress * 100).toInt();
2025-12-11 18:36:11 +05:30
return Card(
2025-12-25 10:26:47 +05:30
elevation: 2,
margin: EdgeInsets.only(bottom: 12 * scale),
2025-12-11 18:36:11 +05:30
color: Colors.white,
shape: RoundedRectangleBorder(
2025-12-25 10:26:47 +05:30
borderRadius: BorderRadius.circular(14),
2025-12-11 18:36:11 +05:30
),
child: Padding(
2025-12-25 10:26:47 +05:30
padding: EdgeInsets.all(12 * scale), // 👈 tighter padding
2025-12-11 18:36:11 +05:30
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
2025-12-25 10:26:47 +05:30
// HEADER
2025-12-11 18:36:11 +05:30
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(
2025-12-25 10:26:47 +05:30
fontSize: 15 * scale, // 👈 slightly smaller
fontWeight: FontWeight.w600,
2025-12-11 18:36:11 +05:30
),
),
2025-12-25 10:26:47 +05:30
getStatusBadge(o['status'], scale),
2025-12-03 11:57:05 +05:30
],
),
2025-12-11 18:36:11 +05:30
2025-12-25 10:26:47 +05:30
SizedBox(height: 6 * scale),
2025-12-11 18:36:11 +05:30
Text(
o['description'],
2025-12-25 10:26:47 +05:30
style: TextStyle(fontSize: 13 * scale),
2025-12-11 18:36:11 +05:30
),
2025-12-25 10:26:47 +05:30
SizedBox(height: 4 * scale),
2025-12-11 18:36:11 +05:30
Text(
"${o['amount']}",
style: TextStyle(
2025-12-25 10:26:47 +05:30
fontSize: 15 * scale,
2025-12-11 18:36:11 +05:30
fontWeight: FontWeight.w600,
),
),
2025-12-25 10:26:47 +05:30
SizedBox(height: 12 * scale),
// PROGRESS HEADER
Align(
alignment: Alignment.centerRight,
child: Text(
"$percent%",
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 11 * scale,
color: Colors.grey.shade700,
),
),
),
2025-12-11 18:36:11 +05:30
_AnimatedProgressBar(progress: progress, scale: scale),
2025-12-25 10:26:47 +05:30
SizedBox(height: 6 * scale),
2025-12-11 18:36:11 +05:30
2025-12-25 10:26:47 +05:30
// PROGRESS LABELS
2025-12-11 18:36:11 +05:30
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
2025-12-25 10:26:47 +05:30
children: const [
Text("Shipment Ready",
style: TextStyle(fontSize: 10, color: Colors.grey)),
Text("Import Custom",
style: TextStyle(fontSize: 10, color: Colors.grey)),
Text("Delivered",
style: TextStyle(fontSize: 10, color: Colors.grey)),
],
),
2025-12-11 18:36:11 +05:30
2025-12-25 10:26:47 +05:30
SizedBox(height: 12 * scale),
2025-12-11 18:36:11 +05:30
2025-12-25 10:26:47 +05:30
// ACTIONS
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_btn(Icons.visibility, "View",
Colors.green.shade700, Colors.green.shade50,
() => _openOrderDetails(o['order_id']), scale),
_btn(Icons.receipt_long, "Invoice",
Colors.orange.shade700, Colors.orange.shade50,
() => _openInvoice(o['order_id']), scale),
_btn(Icons.local_shipping, "Track",
Colors.blue.shade700, Colors.blue.shade50,
() => _openTrack(o['order_id']), scale),
2025-12-11 18:36:11 +05:30
],
2025-12-25 10:26:47 +05:30
),
2025-12-11 18:36:11 +05:30
],
),
),
2025-12-03 11:57:05 +05:30
);
}
2025-12-25 10:26:47 +05:30
Widget _btn(
IconData icon,
String text,
Color fg,
Color bg,
VoidCallback onTap,
double scale,
) {
2025-12-03 11:57:05 +05:30
return InkWell(
onTap: onTap,
2025-12-25 10:26:47 +05:30
borderRadius: BorderRadius.circular(10),
2025-12-03 11:57:05 +05:30
child: Container(
2025-12-25 10:26:47 +05:30
constraints: BoxConstraints(
minWidth: 115 * scale, // 👈 makes button wider
minHeight: 36 * scale, // 👈 makes button taller
),
2025-12-11 18:36:11 +05:30
padding: EdgeInsets.symmetric(
2025-12-25 10:26:47 +05:30
horizontal: 16 * scale, // slightly more horizontal space
vertical: 8 * scale,
2025-12-11 18:36:11 +05:30
),
2025-12-03 11:57:05 +05:30
decoration: BoxDecoration(
2025-12-11 18:36:11 +05:30
color: bg,
2025-12-25 10:26:47 +05:30
borderRadius: BorderRadius.circular(10),
2025-12-11 18:36:11 +05:30
),
child: Row(
2025-12-25 10:26:47 +05:30
mainAxisAlignment: MainAxisAlignment.center, // 👈 centers content
2025-12-11 18:36:11 +05:30
children: [
2025-12-25 10:26:47 +05:30
Icon(icon, size: 16 * scale, color: fg),
SizedBox(width: 6 * scale),
2025-12-11 18:36:11 +05:30
Text(
text,
style: TextStyle(
color: fg,
fontWeight: FontWeight.w600,
2025-12-25 10:26:47 +05:30
fontSize: 12 * scale,
2025-12-11 18:36:11 +05:30
),
),
],
2025-12-03 11:57:05 +05:30
),
),
);
}
2025-12-25 10:26:47 +05:30
// ================= STATUS BADGE =================
2025-12-03 11:57:05 +05:30
2025-12-25 10:26:47 +05:30
Widget getStatusBadge(String? status, double scale) {
final config = statusConfig(status);
final isDomestic = (status ?? '').toLowerCase().contains("domestic");
2025-12-03 11:57:05 +05:30
2025-12-25 10:26:47 +05:30
return Container(
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 6),
decoration: BoxDecoration(
color: config.bg,
borderRadius: BorderRadius.circular(12),
),
child: Text(
isDomestic ? "Domestic\nDistribution" : (status ?? "Unknown"),
textAlign: TextAlign.center,
maxLines: isDomestic ? 2 : 1,
style: TextStyle(
color: config.fg,
fontWeight: FontWeight.w600,
fontSize: 11,
height: 1.2,
),
),
2025-12-11 18:36:11 +05:30
);
}
2025-12-25 10:26:47 +05:30
void _openOrderDetails(String id) =>
Navigator.push(context,
MaterialPageRoute(builder: (_) => OrderDetailScreen(orderId: id)));
void _openInvoice(String id) =>
Navigator.push(context,
MaterialPageRoute(builder: (_) => OrderInvoiceScreen(orderId: id)));
void _openTrack(String id) =>
Navigator.push(context,
MaterialPageRoute(builder: (_) => OrderTrackScreen(orderId: id)));
2025-12-11 18:36:11 +05:30
}
2025-12-23 11:44:56 +05:30
// ================= PROGRESS BAR =================
2025-12-11 18:36:11 +05:30
class _AnimatedProgressBar extends StatelessWidget {
final double progress;
final double scale;
const _AnimatedProgressBar({required this.progress, required this.scale});
@override
Widget build(BuildContext context) {
2025-12-25 10:26:47 +05:30
return LayoutBuilder(builder: (context, c) {
2025-12-23 11:44:56 +05:30
return Stack(
children: [
Container(
2025-12-25 10:26:47 +05:30
height: 8, // 👈 thinner bar
2025-12-23 11:44:56 +05:30
decoration: BoxDecoration(
color: Colors.grey.shade300,
2025-12-25 10:26:47 +05:30
borderRadius: BorderRadius.circular(20),
2025-12-11 18:36:11 +05:30
),
2025-12-23 11:44:56 +05:30
),
AnimatedContainer(
2025-12-25 10:26:47 +05:30
duration: const Duration(milliseconds: 600),
height: 8,
width: c.maxWidth * progress,
2025-12-23 11:44:56 +05:30
decoration: BoxDecoration(
2025-12-25 10:26:47 +05:30
borderRadius: BorderRadius.circular(20),
2025-12-23 11:44:56 +05:30
gradient: const LinearGradient(
2025-12-25 10:26:47 +05:30
colors: [Color(0xFF4F8CFF), Color(0xFF8A4DFF)],
2025-12-11 18:36:11 +05:30
),
),
2025-12-23 11:44:56 +05:30
),
],
);
});
2025-12-03 11:57:05 +05:30
}
}
2025-12-11 18:36:11 +05:30
2025-12-25 10:26:47 +05:30
// ================= STATUS LOGIC =================
2025-12-23 11:44:56 +05:30
2025-12-11 18:36:11 +05:30
double getProgress(String? status) {
final s = (status ?? '').toLowerCase();
2025-12-25 10:26:47 +05:30
if (s.contains("shipment ready")) return 0.05;
if (s.contains("export")) return 0.10;
if (s.contains("international")) return 0.20;
if (s.contains("arrived")) return 0.30;
if (s.contains("import")) return 0.40;
if (s.contains("warehouse")) return 0.50;
if (s.contains("domestic")) return 0.60;
if (s.contains("out for")) return 0.90;
if (s.contains("delivered")) return 1.0;
2025-12-11 18:36:11 +05:30
return 0.05;
}
2025-12-25 10:26:47 +05:30
_StatusConfig statusConfig(String? status) {
2025-12-11 18:36:11 +05:30
final s = (status ?? '').toLowerCase();
2025-12-25 10:26:47 +05:30
if (s.contains("shipment ready")) {
return _StatusConfig(Colors.blue.shade800, Colors.blue.shade50);
}
if (s.contains("export")) {
return _StatusConfig(Colors.purple.shade800, Colors.purple.shade50);
}
if (s.contains("international")) {
return _StatusConfig(Colors.red.shade800, Colors.red.shade50);
}
if (s.contains("arrived")) {
return _StatusConfig(Colors.orange.shade800, Colors.orange.shade50);
}
if (s.contains("import")) {
return _StatusConfig(Colors.teal.shade800, Colors.teal.shade50);
}
if (s.contains("warehouse")) {
return _StatusConfig(Colors.brown.shade800, Colors.brown.shade50);
}
if (s.contains("domestic")) {
return _StatusConfig(Colors.indigo.shade800, Colors.indigo.shade50);
}
if (s.contains("out for")) {
return _StatusConfig(Colors.pink.shade800, Colors.pink.shade50);
}
if (s.contains("delivered")) {
return _StatusConfig(Colors.green.shade800, Colors.green.shade50);
}
return _StatusConfig(Colors.grey.shade800, Colors.grey.shade300);
}
2025-12-11 18:36:11 +05:30
2025-12-25 10:26:47 +05:30
class _StatusConfig {
final Color fg;
final Color bg;
_StatusConfig(this.fg, this.bg);
2025-12-11 18:36:11 +05:30
}