إصلاح توافق فلاتر مع Theme الجديد
This commit is contained in:
@@ -6,9 +6,6 @@ import '../../print.dart';
|
||||
import '../widgets/snackbar.dart';
|
||||
import 'add_invoice_page.dart';
|
||||
|
||||
// نفترض أن هذا الموديل موجود في مشروعك، إذا لم يكن موجوداً يرجى إضافته أو تعديل الاستيراد
|
||||
// import '../../model/invoice_model.dart';
|
||||
|
||||
class InvoiceListPage extends StatefulWidget {
|
||||
const InvoiceListPage({super.key});
|
||||
|
||||
@@ -17,17 +14,11 @@ class InvoiceListPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
List<dynamic> invoices = []; // استخدام dynamic لتجنب مشاكل الموديل إذا اختلف
|
||||
List<dynamic> invoices = [];
|
||||
int totalCount = 0;
|
||||
double totalAmount = 0.0;
|
||||
bool isLoading = true;
|
||||
|
||||
// الألوان "الإيجابية" للتصميم الجديد
|
||||
final Color primaryColor = const Color(0xFF4F46E5); // Indigo
|
||||
final Color secondaryColor = const Color(0xFF818CF8); // Lighter Indigo
|
||||
final Color moneyColor = const Color(0xFF059669); // Emerald Green
|
||||
final Color bgColor = const Color(0xFFF3F4F6); // Light Gray Background
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -46,7 +37,7 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
final data = response;
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
invoices = data['data']; // استخدام البيانات مباشرة
|
||||
invoices = data['data'];
|
||||
totalCount = int.tryParse(data['summary']['count'].toString()) ?? 0;
|
||||
totalAmount =
|
||||
double.tryParse(data['summary']['total'].toString()) ?? 0.0;
|
||||
@@ -66,6 +57,7 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
}
|
||||
|
||||
void _showImageDialog(BuildContext context, String imageUrl) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
showDialog(
|
||||
context: context,
|
||||
builder: (_) => Dialog(
|
||||
@@ -75,8 +67,9 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
children: [
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
color: cs.surface,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
padding: const EdgeInsets.all(5),
|
||||
child: ClipRRect(
|
||||
@@ -93,16 +86,16 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
height: 200,
|
||||
width: 200,
|
||||
child: Center(
|
||||
child: CircularProgressIndicator(color: primaryColor),
|
||||
child: CircularProgressIndicator(color: cs.primary),
|
||||
),
|
||||
);
|
||||
},
|
||||
errorBuilder: (context, error, stackTrace) {
|
||||
return const SizedBox(
|
||||
return SizedBox(
|
||||
height: 150,
|
||||
width: 150,
|
||||
child: Icon(Icons.broken_image,
|
||||
size: 60, color: Colors.grey),
|
||||
child: Icon(Icons.broken_image_rounded,
|
||||
size: 60, color: cs.onSurfaceVariant),
|
||||
);
|
||||
},
|
||||
),
|
||||
@@ -112,11 +105,17 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
Positioned(
|
||||
top: 0,
|
||||
right: 0,
|
||||
child: CircleAvatar(
|
||||
backgroundColor: Colors.white,
|
||||
child: IconButton(
|
||||
icon: const Icon(Icons.close, color: Colors.black),
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: GestureDetector(
|
||||
onTap: () => Navigator.pop(context),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(6),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
child: Icon(Icons.close_rounded,
|
||||
color: cs.onSurfaceVariant, size: 18),
|
||||
),
|
||||
),
|
||||
),
|
||||
@@ -128,17 +127,18 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final cs = Theme.of(context).colorScheme;
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: bgColor,
|
||||
// زر عائم بتصميم متدرج
|
||||
backgroundColor: cs.surface,
|
||||
floatingActionButton: Container(
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(colors: [primaryColor, secondaryColor]),
|
||||
borderRadius: BorderRadius.circular(30),
|
||||
gradient: LinearGradient(colors: [cs.primary, cs.primary.withValues(alpha: 0.7)]),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: primaryColor.withOpacity(0.4),
|
||||
blurRadius: 10,
|
||||
color: cs.primary.withValues(alpha: 0.3),
|
||||
blurRadius: 12,
|
||||
offset: const Offset(0, 4))
|
||||
],
|
||||
),
|
||||
@@ -146,32 +146,29 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
onPressed: () => Get.to(() => AddInvoicePage()),
|
||||
label: const Text('إضافة فاتورة',
|
||||
style: TextStyle(fontWeight: FontWeight.bold)),
|
||||
icon: const Icon(Icons.add),
|
||||
icon: const Icon(Icons.add_rounded),
|
||||
backgroundColor: Colors.transparent,
|
||||
elevation: 0,
|
||||
),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
// 1. رأس الصفحة (Header & Summary)
|
||||
_buildHeader(),
|
||||
|
||||
// 2. قائمة الفواتير
|
||||
_buildHeader(cs),
|
||||
Expanded(
|
||||
child: isLoading
|
||||
? Center(child: CircularProgressIndicator(color: primaryColor))
|
||||
? _buildLoadingState(cs)
|
||||
: invoices.isEmpty
|
||||
? _buildEmptyState()
|
||||
? _buildEmptyState(cs)
|
||||
: RefreshIndicator(
|
||||
onRefresh: fetchInvoices,
|
||||
color: primaryColor,
|
||||
color: cs.primary,
|
||||
child: ListView.builder(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 80),
|
||||
itemCount: invoices.length,
|
||||
physics: const BouncingScrollPhysics(),
|
||||
itemBuilder: (context, index) {
|
||||
final invoice = invoices[index];
|
||||
return _buildInvoiceCard(invoice);
|
||||
return _buildInvoiceCard(invoice, cs);
|
||||
},
|
||||
),
|
||||
),
|
||||
@@ -181,13 +178,12 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
// === تصميم الهيدر (رأس الصفحة) ===
|
||||
Widget _buildHeader() {
|
||||
Widget _buildHeader(ColorScheme cs) {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
padding: EdgeInsets.only(
|
||||
top: MediaQuery.of(context).padding.top + 20,
|
||||
bottom: 30,
|
||||
bottom: 24,
|
||||
left: 20,
|
||||
right: 20,
|
||||
),
|
||||
@@ -195,15 +191,15 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [primaryColor, const Color(0xFF6366F1)],
|
||||
colors: [cs.primary, cs.primary.withValues(alpha: 0.7)],
|
||||
),
|
||||
borderRadius: const BorderRadius.only(
|
||||
bottomLeft: Radius.circular(30),
|
||||
bottomRight: Radius.circular(30),
|
||||
bottomLeft: Radius.circular(24),
|
||||
bottomRight: Radius.circular(24),
|
||||
),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: primaryColor.withOpacity(0.3),
|
||||
color: cs.primary.withValues(alpha: 0.2),
|
||||
blurRadius: 20,
|
||||
offset: const Offset(0, 10),
|
||||
),
|
||||
@@ -211,38 +207,41 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
// العنوان وزر الرجوع
|
||||
Row(
|
||||
children: [
|
||||
IconButton(
|
||||
icon: const Icon(Icons.arrow_back_ios,
|
||||
color: Colors.white, size: 20),
|
||||
onPressed: () => Get.back(),
|
||||
),
|
||||
const Expanded(
|
||||
child: Text(
|
||||
"سجل الفواتير",
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
GestureDetector(
|
||||
onTap: () => Get.back(),
|
||||
child: Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
),
|
||||
child: const Icon(Icons.arrow_back_ios_new_rounded,
|
||||
color: Colors.white, size: 16),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 40), // للمحاذاة
|
||||
const Spacer(),
|
||||
const Text(
|
||||
"سجل الفواتير",
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 18,
|
||||
fontWeight: FontWeight.w700,
|
||||
),
|
||||
),
|
||||
const Spacer(),
|
||||
const SizedBox(width: 34),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 25),
|
||||
|
||||
// بطاقات الملخص
|
||||
const SizedBox(height: 20),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _buildSummaryItem(
|
||||
title: "الإجمالي",
|
||||
value: "${totalAmount.toStringAsFixed(1)} د.أ",
|
||||
icon: Icons.attach_money,
|
||||
icon: Icons.attach_money_rounded,
|
||||
isMoney: true,
|
||||
),
|
||||
),
|
||||
@@ -251,7 +250,7 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
child: _buildSummaryItem(
|
||||
title: "عدد الفواتير",
|
||||
value: "$totalCount",
|
||||
icon: Icons.receipt_long,
|
||||
icon: Icons.receipt_long_rounded,
|
||||
isMoney: false,
|
||||
),
|
||||
),
|
||||
@@ -262,17 +261,18 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildSummaryItem(
|
||||
{required String title,
|
||||
required String value,
|
||||
required IconData icon,
|
||||
required bool isMoney}) {
|
||||
Widget _buildSummaryItem({
|
||||
required String title,
|
||||
required String value,
|
||||
required IconData icon,
|
||||
required bool isMoney,
|
||||
}) {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white.withOpacity(0.2),
|
||||
color: Colors.white.withValues(alpha: 0.2),
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(icon, color: Colors.white, size: 20),
|
||||
@@ -282,21 +282,70 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
value,
|
||||
style: TextStyle(
|
||||
color: isMoney ? const Color(0xFFD1FAE5) : Colors.white,
|
||||
fontSize: 22,
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.w800,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(color: Colors.white.withOpacity(0.8), fontSize: 12),
|
||||
style: const TextStyle(
|
||||
color: Colors.white, fontSize: 11, fontWeight: FontWeight.w500),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// === تصميم بطاقة الفاتورة ===
|
||||
Widget _buildInvoiceCard(dynamic invoice) {
|
||||
// استخراج البيانات بأمان
|
||||
Widget _buildLoadingState(ColorScheme cs) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
SizedBox(
|
||||
width: 40,
|
||||
height: 40,
|
||||
child: CircularProgressIndicator(
|
||||
color: cs.primary,
|
||||
strokeWidth: 2,
|
||||
backgroundColor: cs.primary.withValues(alpha: 0.1),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text('جاري تحميل الفواتير...',
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 13)),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(ColorScheme cs) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Container(
|
||||
padding: const EdgeInsets.all(20),
|
||||
decoration: BoxDecoration(
|
||||
color: cs.surfaceContainerHighest,
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: Icon(Icons.receipt_long_rounded,
|
||||
size: 48, color: cs.onSurfaceVariant),
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text("لا توجد فواتير حالياً",
|
||||
style: TextStyle(color: cs.onSurfaceVariant, fontSize: 14)),
|
||||
const SizedBox(height: 8),
|
||||
TextButton.icon(
|
||||
onPressed: fetchInvoices,
|
||||
icon: const Icon(Icons.refresh_rounded),
|
||||
label: const Text("تحديث"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildInvoiceCard(dynamic invoice, ColorScheme cs) {
|
||||
String name = invoice['name'] ?? 'بدون اسم';
|
||||
String amount = invoice['amount']?.toString() ?? '0';
|
||||
String date = invoice['date'] ?? '';
|
||||
@@ -304,22 +353,16 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
String? imageUrl = invoice['imageLink'];
|
||||
|
||||
return Container(
|
||||
margin: const EdgeInsets.only(bottom: 16),
|
||||
margin: const EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withOpacity(0.03),
|
||||
blurRadius: 15,
|
||||
offset: const Offset(0, 5),
|
||||
),
|
||||
],
|
||||
color: cs.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
child: Material(
|
||||
color: Colors.transparent,
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(20),
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
onTap: () {
|
||||
if (imageUrl != null && imageUrl.isNotEmpty) {
|
||||
_showImageDialog(context, imageUrl);
|
||||
@@ -328,96 +371,93 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
}
|
||||
},
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
padding: const EdgeInsets.all(14),
|
||||
child: Row(
|
||||
children: [
|
||||
// 1. أيقونة أو صورة مصغرة
|
||||
Container(
|
||||
width: 50,
|
||||
height: 50,
|
||||
width: 48,
|
||||
height: 48,
|
||||
decoration: BoxDecoration(
|
||||
color: primaryColor.withOpacity(0.08),
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
color: cs.primary.withValues(alpha: 0.1),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
border: Border.all(color: cs.primary.withValues(alpha: 0.15)),
|
||||
),
|
||||
child: imageUrl != null && imageUrl.isNotEmpty
|
||||
? ClipRRect(
|
||||
borderRadius: BorderRadius.circular(15),
|
||||
borderRadius: BorderRadius.circular(14),
|
||||
child: Image.network(
|
||||
imageUrl,
|
||||
fit: BoxFit.cover,
|
||||
errorBuilder: (_, __, ___) =>
|
||||
Icon(Icons.receipt, color: primaryColor),
|
||||
Icon(Icons.receipt_rounded, color: cs.primary, size: 22),
|
||||
),
|
||||
)
|
||||
: Icon(Icons.receipt_outlined, color: primaryColor),
|
||||
: Icon(Icons.receipt_outlined, color: cs.primary, size: 22),
|
||||
),
|
||||
|
||||
const SizedBox(width: 16),
|
||||
|
||||
// 2. التفاصيل
|
||||
const SizedBox(width: 14),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Text(
|
||||
name,
|
||||
style: const TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 16,
|
||||
color: Color(0xFF1F2937),
|
||||
Expanded(
|
||||
child: Text(
|
||||
name,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.w600,
|
||||
fontSize: 15,
|
||||
color: cs.onSurface,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
Container(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 8, vertical: 4),
|
||||
horizontal: 8, vertical: 3),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.grey[100],
|
||||
color: cs.surface,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(color: cs.outline),
|
||||
),
|
||||
child: Text(
|
||||
"#$invNumber",
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
color: Colors.grey[600],
|
||||
fontWeight: FontWeight.bold),
|
||||
color: cs.onSurfaceVariant,
|
||||
fontWeight: FontWeight.w600),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
date,
|
||||
style: TextStyle(color: Colors.grey[500], fontSize: 12),
|
||||
style: TextStyle(
|
||||
color: cs.onSurfaceVariant, fontSize: 11),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
const SizedBox(width: 12),
|
||||
|
||||
// 3. المبلغ
|
||||
Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.end,
|
||||
children: [
|
||||
Text(
|
||||
amount,
|
||||
style: TextStyle(
|
||||
color: moneyColor,
|
||||
fontWeight: FontWeight.w900,
|
||||
color: const Color(0xFF10B981),
|
||||
fontWeight: FontWeight.w800,
|
||||
fontSize: 18,
|
||||
),
|
||||
),
|
||||
Text(
|
||||
"د.أ",
|
||||
style: TextStyle(
|
||||
color: moneyColor.withOpacity(0.7),
|
||||
color: const Color(0xFF10B981).withValues(alpha: 0.6),
|
||||
fontWeight: FontWeight.w500,
|
||||
fontSize: 12,
|
||||
fontSize: 10,
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -429,26 +469,4 @@ class _InvoiceListPageState extends State<InvoiceListPage> {
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState() {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(Icons.receipt_long_rounded, size: 80, color: Colors.grey[300]),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
"لا توجد فواتير حالياً",
|
||||
style: TextStyle(color: Colors.grey[500], fontSize: 16),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
TextButton.icon(
|
||||
onPressed: fetchInvoices,
|
||||
icon: const Icon(Icons.refresh),
|
||||
label: const Text("تحديث"),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user