add auth, format
This commit is contained in:
@@ -47,8 +47,9 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_tabController..removeListener(_onTabChanged)
|
||||
..dispose();
|
||||
_tabController
|
||||
..removeListener(_onTabChanged)
|
||||
..dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
@@ -57,26 +58,38 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
}
|
||||
|
||||
/// Filter invoices based on tab key
|
||||
List<InvoiceModel> _filterInvoices(List<InvoiceModel> invoices, String tabKey) {
|
||||
List<InvoiceModel> _filterInvoices(
|
||||
List<InvoiceModel> invoices,
|
||||
String tabKey,
|
||||
) {
|
||||
var filtered = List<InvoiceModel>.from(invoices);
|
||||
|
||||
switch (tabKey) {
|
||||
case 'unpaid':
|
||||
// Unpaid tab: issued status only
|
||||
filtered = filtered
|
||||
.where((invoice) => invoice.status == InvoiceStatus.issued && !invoice.isPaid)
|
||||
.where(
|
||||
(invoice) =>
|
||||
invoice.status == InvoiceStatus.issued && !invoice.isPaid,
|
||||
)
|
||||
.toList();
|
||||
break;
|
||||
case 'overdue':
|
||||
// Overdue tab: overdue status
|
||||
filtered = filtered
|
||||
.where((invoice) => invoice.status == InvoiceStatus.overdue || invoice.isOverdue)
|
||||
.where(
|
||||
(invoice) =>
|
||||
invoice.status == InvoiceStatus.overdue || invoice.isOverdue,
|
||||
)
|
||||
.toList();
|
||||
break;
|
||||
case 'paid':
|
||||
// Paid tab: paid status
|
||||
filtered = filtered
|
||||
.where((invoice) => invoice.status == InvoiceStatus.paid || invoice.isPaid)
|
||||
.where(
|
||||
(invoice) =>
|
||||
invoice.status == InvoiceStatus.paid || invoice.isPaid,
|
||||
)
|
||||
.toList();
|
||||
break;
|
||||
case 'all':
|
||||
@@ -96,13 +109,21 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
return {
|
||||
'all': invoices.length,
|
||||
'unpaid': invoices
|
||||
.where((invoice) => invoice.status == InvoiceStatus.issued && !invoice.isPaid)
|
||||
.where(
|
||||
(invoice) =>
|
||||
invoice.status == InvoiceStatus.issued && !invoice.isPaid,
|
||||
)
|
||||
.length,
|
||||
'overdue': invoices
|
||||
.where((invoice) => invoice.status == InvoiceStatus.overdue || invoice.isOverdue)
|
||||
.where(
|
||||
(invoice) =>
|
||||
invoice.status == InvoiceStatus.overdue || invoice.isOverdue,
|
||||
)
|
||||
.length,
|
||||
'paid': invoices
|
||||
.where((invoice) => invoice.status == InvoiceStatus.paid || invoice.isPaid)
|
||||
.where(
|
||||
(invoice) => invoice.status == InvoiceStatus.paid || invoice.isPaid,
|
||||
)
|
||||
.length,
|
||||
};
|
||||
}
|
||||
@@ -190,7 +211,10 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
child: TabBarView(
|
||||
controller: _tabController,
|
||||
children: _tabs.map((tab) {
|
||||
final filteredInvoices = _filterInvoices(allInvoices, tab['key']!);
|
||||
final filteredInvoices = _filterInvoices(
|
||||
allInvoices,
|
||||
tab['key']!,
|
||||
);
|
||||
|
||||
return CustomScrollView(
|
||||
slivers: [
|
||||
@@ -200,21 +224,25 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
sliver: filteredInvoices.isEmpty
|
||||
? _buildEmptyState(tab['label']!)
|
||||
: SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final invoice = filteredInvoices[index];
|
||||
return InvoiceCard(
|
||||
invoice: invoice,
|
||||
onTap: () {
|
||||
context.push('/payments/${invoice.invoiceId}');
|
||||
},
|
||||
onPaymentTap: () {
|
||||
context.push('/payments/${invoice.invoiceId}');
|
||||
},
|
||||
);
|
||||
},
|
||||
childCount: filteredInvoices.length,
|
||||
),
|
||||
delegate: SliverChildBuilderDelegate((
|
||||
context,
|
||||
index,
|
||||
) {
|
||||
final invoice = filteredInvoices[index];
|
||||
return InvoiceCard(
|
||||
invoice: invoice,
|
||||
onTap: () {
|
||||
context.push(
|
||||
'/payments/${invoice.invoiceId}',
|
||||
);
|
||||
},
|
||||
onPaymentTap: () {
|
||||
context.push(
|
||||
'/payments/${invoice.invoiceId}',
|
||||
);
|
||||
},
|
||||
);
|
||||
}, childCount: filteredInvoices.length),
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -240,9 +268,7 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
foregroundColor: AppColors.grey900,
|
||||
centerTitle: false,
|
||||
),
|
||||
body: const Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
body: const Center(child: CircularProgressIndicator()),
|
||||
),
|
||||
error: (error, stack) => Scaffold(
|
||||
backgroundColor: const Color(0xFFF4F6F8),
|
||||
@@ -281,10 +307,7 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
error.toString(),
|
||||
style: const TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: const TextStyle(fontSize: 14, color: AppColors.grey500),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
@@ -339,10 +362,7 @@ class _PaymentsPageState extends ConsumerState<PaymentsPage>
|
||||
const SizedBox(height: 8),
|
||||
const Text(
|
||||
'Kéo xuống để làm mới',
|
||||
style: TextStyle(
|
||||
fontSize: 14,
|
||||
color: AppColors.grey500,
|
||||
),
|
||||
style: TextStyle(fontSize: 14, color: AppColors.grey500),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
Reference in New Issue
Block a user