minor changes
This commit is contained in:
@@ -1,18 +1,14 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'dart:io';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
|
||||
import '../services/chat_service.dart';
|
||||
import '../services/reverb_socket_service.dart';
|
||||
import '../services/dio_client.dart';
|
||||
import '../providers/chat_unread_provider.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'dart:io';
|
||||
import 'package:file_selector/file_selector.dart';
|
||||
import 'chat_file_viewer.dart';
|
||||
import '../widgets/chat_file_preview.dart';
|
||||
|
||||
|
||||
|
||||
import 'chat_file_viewer.dart';
|
||||
|
||||
class ChatScreen extends StatefulWidget {
|
||||
const ChatScreen({super.key});
|
||||
@@ -24,6 +20,7 @@ class ChatScreen extends StatefulWidget {
|
||||
class _ChatScreenState extends State<ChatScreen> {
|
||||
final TextEditingController _messageCtrl = TextEditingController();
|
||||
final ScrollController _scrollCtrl = ScrollController();
|
||||
|
||||
Map<String, dynamic>? uploadingMessage;
|
||||
|
||||
late ChatService _chatService;
|
||||
@@ -33,22 +30,18 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
List<Map<String, dynamic>> messages = [];
|
||||
bool isLoading = true;
|
||||
|
||||
// ============================
|
||||
// INIT STATE
|
||||
// ============================
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
_chatService = ChatService(DioClient.getInstance(context));
|
||||
|
||||
// 🔔 Mark chat as OPEN (important)
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.read<ChatUnreadProvider>().setChatOpen(true);
|
||||
});
|
||||
|
||||
_initChat();
|
||||
}
|
||||
|
||||
String _guessMimeType(String path) {
|
||||
final lower = path.toLowerCase();
|
||||
if (lower.endsWith('.jpg') || lower.endsWith('.png')) return 'image/*';
|
||||
@@ -63,7 +56,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
final file = File(picked.path);
|
||||
|
||||
// 1️⃣ Show uploading UI
|
||||
setState(() {
|
||||
uploadingMessage = {
|
||||
'local_file': file,
|
||||
@@ -72,44 +64,26 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
};
|
||||
});
|
||||
|
||||
// 2️⃣ Upload (NO adding message)
|
||||
await _chatService.sendFile(
|
||||
ticketId!,
|
||||
file,
|
||||
onProgress: (progress) {
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
uploadingMessage!['progress'] = progress;
|
||||
});
|
||||
setState(() => uploadingMessage!['progress'] = progress);
|
||||
},
|
||||
);
|
||||
|
||||
// 3️⃣ Remove sending bubble ONLY
|
||||
if (!mounted) return;
|
||||
setState(() {
|
||||
uploadingMessage = null;
|
||||
});
|
||||
|
||||
// 🚫 DO NOT add message here
|
||||
// WebSocket will handle it
|
||||
setState(() => uploadingMessage = null);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
// ============================
|
||||
// INIT CHAT
|
||||
// ============================
|
||||
Future<void> _initChat() async {
|
||||
// 1️⃣ Start chat
|
||||
final ticketRes = await _chatService.startChat();
|
||||
ticketId = ticketRes['ticket']['id'];
|
||||
|
||||
// 2️⃣ Load messages
|
||||
final msgs = await _chatService.getMessages(ticketId!);
|
||||
messages = List<Map<String, dynamic>>.from(msgs);
|
||||
|
||||
// 3️⃣ Realtime socket
|
||||
await _socket.connect(
|
||||
context: context,
|
||||
ticketId: ticketId!,
|
||||
@@ -117,20 +91,12 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
final incomingClientId = msg['client_id'];
|
||||
|
||||
setState(() {
|
||||
// 🧹 Remove local temp message with same client_id
|
||||
messages.removeWhere(
|
||||
(m) => m['client_id'] != null &&
|
||||
m['client_id'] == incomingClientId,
|
||||
);
|
||||
|
||||
// ✅ Add confirmed socket message
|
||||
messages.removeWhere((m) => m['client_id'] == incomingClientId);
|
||||
messages.add(msg);
|
||||
});
|
||||
|
||||
_scrollToBottom();
|
||||
},
|
||||
|
||||
|
||||
onAdminMessage: () {
|
||||
if (!mounted) {
|
||||
context.read<ChatUnreadProvider>().increment();
|
||||
@@ -138,37 +104,30 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
},
|
||||
);
|
||||
|
||||
|
||||
|
||||
|
||||
if (!mounted) return;
|
||||
setState(() => isLoading = false);
|
||||
_scrollToBottom();
|
||||
}
|
||||
|
||||
// ============================
|
||||
// SCROLL
|
||||
// ============================
|
||||
void _scrollToBottom() {
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (_scrollCtrl.hasClients) {
|
||||
_scrollCtrl.jumpTo(_scrollCtrl.position.maxScrollExtent);
|
||||
_scrollCtrl.animateTo(
|
||||
_scrollCtrl.position.maxScrollExtent,
|
||||
duration: const Duration(milliseconds: 250),
|
||||
curve: Curves.easeOut,
|
||||
);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
// ============================
|
||||
// SEND MESSAGE
|
||||
// ============================
|
||||
Future<void> _sendMessage() async {
|
||||
final text = _messageCtrl.text.trim();
|
||||
if (text.isEmpty || ticketId == null) return;
|
||||
|
||||
_messageCtrl.clear();
|
||||
|
||||
final clientId = DateTime.now().millisecondsSinceEpoch.toString();
|
||||
|
||||
// 1️⃣ ADD LOCAL MESSAGE IMMEDIATELY
|
||||
setState(() {
|
||||
messages.add({
|
||||
'client_id': clientId,
|
||||
@@ -182,7 +141,6 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
|
||||
_scrollToBottom();
|
||||
|
||||
// 2️⃣ SEND TO SERVER
|
||||
await _chatService.sendMessage(
|
||||
ticketId!,
|
||||
message: text,
|
||||
@@ -190,28 +148,68 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// ============================
|
||||
// DISPOSE
|
||||
// ============================
|
||||
@override
|
||||
void dispose() {
|
||||
// 🔕 Mark chat CLOSED
|
||||
context.read<ChatUnreadProvider>().setChatOpen(false);
|
||||
|
||||
_socket.disconnect();
|
||||
_messageCtrl.dispose();
|
||||
_scrollCtrl.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
// ============================
|
||||
// UI
|
||||
// ============================
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(title: const Text("Support Chat")),
|
||||
appBar: PreferredSize(
|
||||
preferredSize: const Size.fromHeight(56),
|
||||
child: AnimatedContainer(
|
||||
duration: const Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
decoration: const BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF2196F3),
|
||||
Color(0xFF1565C0),
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black26,
|
||||
blurRadius: 10,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: AppBar(
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
leading: Padding(
|
||||
padding: const EdgeInsets.only(left: 12),
|
||||
child: CircleAvatar(
|
||||
radius: 18,
|
||||
backgroundColor: Colors.white,
|
||||
child: Icon(
|
||||
Icons.support_agent,
|
||||
color: Colors.blue,
|
||||
size: 20,
|
||||
),
|
||||
),
|
||||
),
|
||||
title: const Text(
|
||||
"Support Chat",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
centerTitle: false,
|
||||
iconTheme: const IconThemeData(color: Colors.white),
|
||||
),
|
||||
),
|
||||
),
|
||||
body: isLoading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: Column(
|
||||
@@ -223,100 +221,54 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// Future<void> _openUrl(String url) async {
|
||||
// final uri = Uri.parse(url);
|
||||
//
|
||||
// if (await canLaunchUrl(uri)) {
|
||||
// await launchUrl(
|
||||
// uri,
|
||||
// mode: LaunchMode.externalApplication,
|
||||
// );
|
||||
// } else {
|
||||
// debugPrint("❌ Cannot launch URL: $url");
|
||||
// }
|
||||
// }
|
||||
|
||||
|
||||
|
||||
Widget _buildMessageContent({
|
||||
String? message,
|
||||
String? filePath,
|
||||
String? fileType,
|
||||
required bool isUser,
|
||||
}) {
|
||||
final textColor = isUser ? Colors.white : Colors.black;
|
||||
|
||||
if (filePath == null) {
|
||||
return Text(message ?? '', style: TextStyle(color: textColor));
|
||||
}
|
||||
|
||||
final url = "${DioClient.baseUrl}/storage/$filePath";
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () {
|
||||
ChatFileViewer.open(
|
||||
context,
|
||||
url: url,
|
||||
fileType: fileType ?? '',
|
||||
);
|
||||
},
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Icon(_iconForFile(fileType), color: textColor),
|
||||
const SizedBox(width: 8),
|
||||
Text(
|
||||
_labelForFile(fileType),
|
||||
style: TextStyle(color: textColor),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
IconData _iconForFile(String? type) {
|
||||
if (type == null) return Icons.insert_drive_file;
|
||||
if (type.startsWith('image/')) return Icons.image;
|
||||
if (type.startsWith('video/')) return Icons.play_circle_fill;
|
||||
if (type == 'application/pdf') return Icons.picture_as_pdf;
|
||||
return Icons.insert_drive_file;
|
||||
}
|
||||
|
||||
String _labelForFile(String? type) {
|
||||
if (type == null) return "File";
|
||||
if (type.startsWith('image/')) return "Image";
|
||||
if (type.startsWith('video/')) return "Video";
|
||||
if (type == 'application/pdf') return "PDF";
|
||||
return "Download file";
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
Widget _buildMessages() {
|
||||
return ListView(
|
||||
controller: _scrollCtrl,
|
||||
padding: const EdgeInsets.all(12),
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
||||
children: [
|
||||
// EXISTING MESSAGES
|
||||
...messages.map((msg) {
|
||||
final isUser = msg['sender_type'] == 'App\\Models\\User';
|
||||
|
||||
return Align(
|
||||
alignment: isUser ? Alignment.centerRight : Alignment.centerLeft,
|
||||
alignment:
|
||||
isUser ? Alignment.centerRight : Alignment.centerLeft,
|
||||
child: Container(
|
||||
constraints: const BoxConstraints(maxWidth: 280),
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
padding: const EdgeInsets.all(10),
|
||||
padding: const EdgeInsets.all(12),
|
||||
decoration: BoxDecoration(
|
||||
color: isUser ? Colors.blue : Colors.grey.shade300,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
color: isUser ? null : Colors.white,
|
||||
gradient: isUser
|
||||
? LinearGradient(
|
||||
colors: [
|
||||
Colors.lightBlueAccent,
|
||||
Colors.blue.shade700,
|
||||
],
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
)
|
||||
: null,
|
||||
borderRadius: BorderRadius.only(
|
||||
topLeft: const Radius.circular(16),
|
||||
topRight: const Radius.circular(16),
|
||||
bottomLeft:
|
||||
isUser ? const Radius.circular(16) : Radius.zero,
|
||||
bottomRight:
|
||||
isUser ? Radius.zero : const Radius.circular(16),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 6,
|
||||
),
|
||||
],
|
||||
),
|
||||
child: msg['file_path'] == null
|
||||
? Text(
|
||||
msg['message'] ?? '',
|
||||
style: TextStyle(
|
||||
color: isUser ? Colors.white : Colors.black,
|
||||
color: isUser ? Colors.white : Colors.blue,
|
||||
fontSize: 15,
|
||||
),
|
||||
)
|
||||
: ChatFilePreview(
|
||||
@@ -327,75 +279,49 @@ class _ChatScreenState extends State<ChatScreen> {
|
||||
),
|
||||
);
|
||||
}),
|
||||
|
||||
// ⏳ UPLOADING MESSAGE
|
||||
if (uploadingMessage != null)
|
||||
Align(
|
||||
alignment: Alignment.centerRight,
|
||||
child: Container(
|
||||
margin: const EdgeInsets.symmetric(vertical: 6),
|
||||
padding: const EdgeInsets.all(10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.blue,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ChatFilePreview(
|
||||
filePath: uploadingMessage!['local_file'].path,
|
||||
fileType: uploadingMessage!['file_type'],
|
||||
isUser: true,
|
||||
isLocal: true,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
LinearProgressIndicator(
|
||||
value: uploadingMessage!['progress'],
|
||||
backgroundColor: Colors.white24,
|
||||
valueColor:
|
||||
const AlwaysStoppedAnimation(Colors.white),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
const Text(
|
||||
"Sending…",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 12,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
Widget _buildInput() {
|
||||
return SafeArea(
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.attach_file),
|
||||
onPressed: _pickAndSendFile,
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _messageCtrl,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Type message",
|
||||
border: InputBorder.none,
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(8),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 12),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(24),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.05),
|
||||
blurRadius: 6,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.send),
|
||||
onPressed: _sendMessage,
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.attach_file),
|
||||
onPressed: _pickAndSendFile,
|
||||
),
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _messageCtrl,
|
||||
decoration: const InputDecoration(
|
||||
hintText: "Type a message…",
|
||||
border: InputBorder.none,
|
||||
),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
icon: const Icon(Icons.send, color: Colors.blue),
|
||||
onPressed: _sendMessage,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -541,7 +541,22 @@ class _DashboardScreenState extends State<DashboardScreen>
|
||||
vertical: 6 * scale,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(.2),
|
||||
gradient: (m['status'] ?? '')
|
||||
.toString()
|
||||
.toLowerCase() ==
|
||||
'active'
|
||||
? const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF2ECC71), // Green
|
||||
Color(0xFF16A085), // Teal Green
|
||||
],
|
||||
)
|
||||
: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFFE74C3C), // Red
|
||||
Color(0xFFC0392B), // Dark Red
|
||||
],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(8 * scale),
|
||||
),
|
||||
child: Text(
|
||||
@@ -552,7 +567,7 @@ class _DashboardScreenState extends State<DashboardScreen>
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -175,4 +175,4 @@ class _InvoiceDetailScreenState extends State<InvoiceDetailScreen> {
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -24,19 +24,16 @@ class _MarkListScreenState extends State<MarkListScreen> {
|
||||
Widget build(BuildContext context) {
|
||||
final marks = Provider.of<MarkListProvider>(context);
|
||||
|
||||
// Responsive scale factor
|
||||
final screenWidth = MediaQuery.of(context).size.width;
|
||||
final scale = (screenWidth / 390).clamp(0.82, 1.35);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: Colors.white,
|
||||
|
||||
appBar: AppBar(
|
||||
backgroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
centerTitle: true,
|
||||
iconTheme: const IconThemeData(color: Colors.black),
|
||||
|
||||
title: Text(
|
||||
"All Mark Numbers",
|
||||
style: TextStyle(
|
||||
@@ -50,14 +47,31 @@ class _MarkListScreenState extends State<MarkListScreen> {
|
||||
body: marks.loading
|
||||
? const Center(child: CircularProgressIndicator())
|
||||
: ListView.builder(
|
||||
padding: EdgeInsets.all(10 * scale), // smaller padding
|
||||
padding: EdgeInsets.all(10 * scale),
|
||||
itemCount: marks.marks.length,
|
||||
itemBuilder: (_, i) {
|
||||
final m = marks.marks[i];
|
||||
final status =
|
||||
(m['status'] ?? '').toString().toLowerCase();
|
||||
|
||||
final LinearGradient statusGradient =
|
||||
status == 'active'
|
||||
? const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF2ECC71), // Green
|
||||
Color(0xFF1E8449), // Deep Emerald
|
||||
],
|
||||
)
|
||||
: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFFE74C3C), // Red
|
||||
Color(0xFFC0392B), // Dark Red
|
||||
],
|
||||
);
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 10 * scale), // reduced margin
|
||||
padding: EdgeInsets.all(12 * scale), // smaller padding
|
||||
margin: EdgeInsets.only(bottom: 10 * scale),
|
||||
padding: EdgeInsets.all(12 * scale),
|
||||
decoration: BoxDecoration(
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
@@ -67,16 +81,15 @@ class _MarkListScreenState extends State<MarkListScreen> {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
),
|
||||
borderRadius: BorderRadius.circular(14 * scale), // smaller radius
|
||||
borderRadius: BorderRadius.circular(14 * scale),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.06),
|
||||
blurRadius: 5 * scale, // smaller shadow
|
||||
blurRadius: 5 * scale,
|
||||
offset: Offset(0, 2 * scale),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -85,24 +98,20 @@ class _MarkListScreenState extends State<MarkListScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// MARK NUMBER
|
||||
Text(
|
||||
m['mark_no'],
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 16 * scale, // reduced font
|
||||
fontSize: 16 * scale,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 3 * scale),
|
||||
|
||||
// ROUTE
|
||||
Text(
|
||||
"${m['origin']} → ${m['destination']}",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 13 * scale, // reduced font
|
||||
fontSize: 13 * scale,
|
||||
fontWeight: FontWeight.w500,
|
||||
),
|
||||
),
|
||||
@@ -110,21 +119,21 @@ class _MarkListScreenState extends State<MarkListScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// STATUS BADGE
|
||||
// STATUS BADGE (GREEN / RED)
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 10 * scale,
|
||||
vertical: 5 * scale, // smaller badge
|
||||
vertical: 5 * scale,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.92),
|
||||
borderRadius: BorderRadius.circular(24 * scale),
|
||||
gradient: statusGradient,
|
||||
borderRadius: BorderRadius.circular(20 * scale),
|
||||
),
|
||||
child: Text(
|
||||
m['status'],
|
||||
style: TextStyle(
|
||||
fontSize: 11.5 * scale,
|
||||
color: Colors.black87,
|
||||
color: Colors.white,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
|
||||
@@ -84,7 +84,6 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
children: [
|
||||
_headerCard(scale),
|
||||
|
||||
// SUMMARY SECTION
|
||||
_sectionHeader("Invoice Summary", Icons.receipt, s1, () {
|
||||
setState(() => s1 = !s1);
|
||||
}, scale),
|
||||
@@ -92,12 +91,8 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
_detailRow(Icons.numbers, "Invoice No", invoice['invoice_number'], scale),
|
||||
_detailRow(Icons.calendar_month, "Invoice Date", invoice['invoice_date'], scale),
|
||||
_detailRow(Icons.date_range, "Due Date", invoice['due_date'], scale),
|
||||
// _detailRow(Icons.payment, "Payment Method", invoice['payment_method'], scale),
|
||||
// _detailRow(Icons.confirmation_number, "Reference No",
|
||||
// invoice['reference_no'], scale),
|
||||
], scale),
|
||||
|
||||
// AMOUNT SECTION
|
||||
_sectionHeader("Amount Details", Icons.currency_rupee, s2, () {
|
||||
setState(() => s2 = !s2);
|
||||
}, scale),
|
||||
@@ -109,7 +104,6 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
invoice['final_amount_with_gst'], scale),
|
||||
], scale),
|
||||
|
||||
// CUSTOMER SECTION
|
||||
_sectionHeader("Customer Details", Icons.person, s3, () {
|
||||
setState(() => s3 = !s3);
|
||||
}, scale),
|
||||
@@ -121,7 +115,6 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
_detailRow(Icons.location_on, "Address", invoice['customer_address'], scale),
|
||||
], scale),
|
||||
|
||||
// ITEMS SECTION
|
||||
_sectionHeader("Invoice Items", Icons.shopping_cart, s4, () {
|
||||
setState(() => s4 = !s4);
|
||||
}, scale),
|
||||
@@ -139,44 +132,63 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
|
||||
// ---------------- HEADER CARD ----------------
|
||||
Widget _headerCard(double scale) {
|
||||
final statusColor = getInvoiceStatusColor(invoice["status"]);
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.all(18 * scale),
|
||||
margin: EdgeInsets.only(bottom: 18 * scale),
|
||||
decoration: BoxDecoration(
|
||||
gradient:
|
||||
LinearGradient(colors: [Colors.indigo.shade400, Colors.blue.shade600]),
|
||||
gradient: LinearGradient(
|
||||
colors: [Colors.indigo.shade400, Colors.blue.shade600],
|
||||
),
|
||||
borderRadius: BorderRadius.circular(16 * scale),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
blurRadius: 10 * scale,
|
||||
color: Colors.black.withOpacity(.15),
|
||||
offset: Offset(0, 3 * scale))
|
||||
blurRadius: 10 * scale,
|
||||
color: Colors.black.withOpacity(.15),
|
||||
offset: Offset(0, 3 * scale),
|
||||
)
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text("Invoice #${invoice['invoice_number'] ?? '-'}",
|
||||
style: TextStyle(
|
||||
fontSize: 22 * scale,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white)),
|
||||
Text(
|
||||
"Invoice #${invoice['invoice_number'] ?? '-'}",
|
||||
style: TextStyle(
|
||||
fontSize: 22 * scale,
|
||||
fontWeight: FontWeight.bold,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 6 * scale),
|
||||
Text("Date: ${invoice['invoice_date'] ?? '-'}",
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14 * scale)),
|
||||
Text(
|
||||
"Date: ${invoice['invoice_date'] ?? '-'}",
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14 * scale),
|
||||
),
|
||||
SizedBox(height: 10 * scale),
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 6 * scale, horizontal: 14 * scale),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(.2),
|
||||
color: Colors.white, // ✅ Always white
|
||||
borderRadius: BorderRadius.circular(50 * scale),
|
||||
border: Border.all(
|
||||
color: statusColor, // ✅ Different for each status
|
||||
width: 1.4 * scale,
|
||||
),
|
||||
),
|
||||
child: Text(
|
||||
invoice["status"]?.toString() ?? "Unknown",
|
||||
style: TextStyle(color: Colors.white, fontSize: 14 * scale),
|
||||
(invoice["status"] ?? "Unknown").toString().toUpperCase(),
|
||||
style: TextStyle(
|
||||
color: statusColor, // ✅ Text color changes
|
||||
fontSize: 14 * scale,
|
||||
fontWeight: FontWeight.bold,
|
||||
letterSpacing: 0.5,
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -199,11 +211,14 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
children: [
|
||||
Icon(icon, color: Colors.white, size: 20 * scale),
|
||||
SizedBox(width: 10 * scale),
|
||||
Text(title,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15 * scale,
|
||||
color: Colors.white)),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15 * scale,
|
||||
color: Colors.white,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
AnimatedRotation(
|
||||
turns: expanded ? .5 : 0,
|
||||
@@ -234,9 +249,10 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
blurRadius: 8 * scale,
|
||||
offset: Offset(0, 3 * scale),
|
||||
color: Colors.black.withOpacity(.08)),
|
||||
blurRadius: 8 * scale,
|
||||
offset: Offset(0, 3 * scale),
|
||||
color: Colors.black.withOpacity(.08),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(children: children),
|
||||
@@ -256,16 +272,19 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
Icon(icon, color: Colors.blueGrey, size: 20 * scale),
|
||||
SizedBox(width: 10 * scale),
|
||||
Expanded(
|
||||
child: Text(label,
|
||||
style: TextStyle(
|
||||
color: Colors.grey.shade700, fontSize: 14 * scale)),
|
||||
child: Text(
|
||||
label,
|
||||
style: TextStyle(color: Colors.grey.shade700, fontSize: 14 * scale),
|
||||
),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
value?.toString() ?? "N/A",
|
||||
textAlign: TextAlign.end,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold, fontSize: 15 * scale),
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 15 * scale,
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
@@ -287,16 +306,16 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
color: Colors.white,
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
blurRadius: 8 * scale,
|
||||
offset: Offset(0, 3 * scale),
|
||||
color: Colors.black.withOpacity(.08)),
|
||||
blurRadius: 8 * scale,
|
||||
offset: Offset(0, 3 * scale),
|
||||
color: Colors.black.withOpacity(.08),
|
||||
),
|
||||
],
|
||||
border: Border.all(color: Colors.grey.shade300, width: 1),
|
||||
),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// TITLE
|
||||
Row(
|
||||
children: [
|
||||
Container(
|
||||
@@ -313,15 +332,14 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
child: Text(
|
||||
item['description'] ?? "Item",
|
||||
style: TextStyle(
|
||||
fontSize: 16 * scale, fontWeight: FontWeight.w600),
|
||||
fontSize: 16 * scale,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(height: 14 * scale),
|
||||
|
||||
// QTY & PRICE
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -329,10 +347,7 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
_itemBadge(Icons.currency_rupee, "Price", "₹$price", false, scale),
|
||||
],
|
||||
),
|
||||
|
||||
SizedBox(height: 12 * scale),
|
||||
|
||||
// TOTAL
|
||||
Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
vertical: 10 * scale, horizontal: 14 * scale),
|
||||
@@ -384,8 +399,9 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
borderRadius: BorderRadius.circular(12 * scale),
|
||||
color: highlight ? Colors.indigo.shade50 : Colors.grey.shade100,
|
||||
border: Border.all(
|
||||
color: highlight ? Colors.indigo : Colors.grey.shade300,
|
||||
width: highlight ? 1.5 * scale : 1),
|
||||
color: highlight ? Colors.indigo : Colors.grey.shade300,
|
||||
width: highlight ? 1.5 * scale : 1,
|
||||
),
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
@@ -414,3 +430,22 @@ class _OrderInvoiceScreenState extends State<OrderInvoiceScreen>
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
// ---------------- STATUS COLOR HELPER ----------------
|
||||
|
||||
Color getInvoiceStatusColor(String? status) {
|
||||
final s = (status ?? '')
|
||||
.toLowerCase()
|
||||
.replaceAll('_', ' ')
|
||||
.replaceAll('-', ' ')
|
||||
.trim();
|
||||
|
||||
if (s == 'paid') return Colors.green.shade600;
|
||||
if (s == 'pending') return Colors.orange.shade600;
|
||||
if (s == 'overdue') return Colors.red.shade600;
|
||||
if (s == 'cancelled' || s == 'canceled') return Colors.grey.shade600;
|
||||
if (s == 'in progress') return Colors.blue.shade600;
|
||||
if (s == 'draft') return Colors.purple.shade600;
|
||||
|
||||
return Colors.blueGrey;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
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) ||
|
||||
@@ -45,7 +44,7 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
|
||||
return Column(
|
||||
children: [
|
||||
// ⭐⭐ WHITE ELEVATED SEARCH BAR ⭐⭐
|
||||
// SEARCH BAR
|
||||
Container(
|
||||
margin: EdgeInsets.fromLTRB(16 * scale, 16 * scale, 16 * scale, 10 * scale),
|
||||
padding: EdgeInsets.symmetric(horizontal: 14 * scale),
|
||||
@@ -63,11 +62,8 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.search,
|
||||
size: 22 * scale, color: Colors.grey.shade700),
|
||||
|
||||
Icon(Icons.search, size: 22 * scale, color: Colors.grey.shade700),
|
||||
SizedBox(width: 10 * scale),
|
||||
|
||||
Expanded(
|
||||
child: TextField(
|
||||
onChanged: (value) => setState(() => searchQuery = value),
|
||||
@@ -86,7 +82,7 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
),
|
||||
),
|
||||
|
||||
// LIST OF ORDERS
|
||||
// ORDER LIST
|
||||
Expanded(
|
||||
child: ListView.builder(
|
||||
padding: EdgeInsets.all(16 * scale),
|
||||
@@ -101,7 +97,6 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// ORDER CARD UI
|
||||
Widget _orderCard(Map<String, dynamic> o, double scale) {
|
||||
final progress = getProgress(o['status']);
|
||||
final badgeColor = getStatusColor(o['status']);
|
||||
@@ -118,7 +113,6 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// TOP ROW
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -151,12 +145,7 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
),
|
||||
|
||||
SizedBox(height: 10 * scale),
|
||||
|
||||
Text(
|
||||
o['description'],
|
||||
style: TextStyle(fontSize: 14 * scale),
|
||||
),
|
||||
|
||||
Text(o['description'], style: TextStyle(fontSize: 14 * scale)),
|
||||
SizedBox(height: 5 * scale),
|
||||
|
||||
Text(
|
||||
@@ -168,12 +157,9 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
),
|
||||
|
||||
SizedBox(height: 18 * scale),
|
||||
|
||||
_AnimatedProgressBar(progress: progress, scale: scale),
|
||||
|
||||
SizedBox(height: 18 * scale),
|
||||
|
||||
// BUTTONS
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
@@ -193,21 +179,14 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// BUTTON UI
|
||||
Widget _btn(IconData icon, String text, Color fg, Color bg,
|
||||
VoidCallback onTap, double scale) {
|
||||
return InkWell(
|
||||
borderRadius: BorderRadius.circular(12 * scale),
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 20 * scale,
|
||||
vertical: 12 * scale,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: bg,
|
||||
borderRadius: BorderRadius.circular(12 * scale),
|
||||
),
|
||||
padding: EdgeInsets.symmetric(horizontal: 20 * scale, vertical: 12 * scale),
|
||||
decoration: BoxDecoration(color: bg, borderRadius: BorderRadius.circular(12 * scale)),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(icon, size: 18 * scale, color: fg),
|
||||
@@ -226,30 +205,24 @@ class _OrdersScreenState extends State<OrdersScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
// NAVIGATION
|
||||
void _openOrderDetails(String id) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => OrderDetailScreen(orderId: id)),
|
||||
);
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (_) => OrderDetailScreen(orderId: id)));
|
||||
}
|
||||
|
||||
void _openInvoice(String id) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => OrderInvoiceScreen(orderId: id)),
|
||||
);
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (_) => OrderInvoiceScreen(orderId: id)));
|
||||
}
|
||||
|
||||
void _openTrack(String id) {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(builder: (_) => OrderTrackScreen(orderId: id)),
|
||||
);
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (_) => OrderTrackScreen(orderId: id)));
|
||||
}
|
||||
}
|
||||
|
||||
// PROGRESS BAR
|
||||
// ================= PROGRESS BAR =================
|
||||
|
||||
class _AnimatedProgressBar extends StatelessWidget {
|
||||
final double progress;
|
||||
final double scale;
|
||||
@@ -258,61 +231,65 @@ class _AnimatedProgressBar extends StatelessWidget {
|
||||
|
||||
@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),
|
||||
return LayoutBuilder(builder: (context, constraints) {
|
||||
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: constraints.maxWidth * progress,
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadius.circular(20 * scale),
|
||||
gradient: const LinearGradient(
|
||||
colors: [
|
||||
Color(0xFF4F8CFF),
|
||||
Color(0xFF8A4DFF),
|
||||
],
|
||||
),
|
||||
),
|
||||
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),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// PROGRESS VALUES
|
||||
// ================= FIXED STATUS LOGIC =================
|
||||
|
||||
double getProgress(String? status) {
|
||||
final s = (status ?? '').toLowerCase();
|
||||
final s = (status ?? '')
|
||||
.toLowerCase()
|
||||
.replaceAll('_', ' ')
|
||||
.replaceAll('-', ' ')
|
||||
.trim();
|
||||
|
||||
if (s == "pending") return 0.25;
|
||||
if (s == "loading") return 0.40;
|
||||
if (s == "in transit" || s == "intransit") return 0.65;
|
||||
if (s.contains("transit")) 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();
|
||||
final s = (status ?? '')
|
||||
.toLowerCase()
|
||||
.replaceAll('_', ' ')
|
||||
.replaceAll('-', ' ')
|
||||
.trim();
|
||||
|
||||
if (s == "pending") return Colors.orange;
|
||||
if (s == "loading") return Colors.amber.shade800;
|
||||
if (s == "in transit" || s == "intransit") return Colors.red;
|
||||
if (s.contains("transit")) return Colors.red;
|
||||
if (s == "dispatched") return Colors.blue.shade700;
|
||||
if (s == "delivered") return Colors.green.shade700;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user