refactor: enhance invoice display logic and add empty state in BillingView
This commit is contained in:
@@ -10,7 +10,6 @@ import '../blocs/billing_state.dart';
|
||||
import '../widgets/invoice_history_section.dart';
|
||||
import '../widgets/payment_method_card.dart';
|
||||
import '../widgets/pending_invoices_section.dart';
|
||||
import '../widgets/savings_card.dart';
|
||||
import '../widgets/spending_breakdown_card.dart';
|
||||
|
||||
/// The entry point page for the client billing feature.
|
||||
@@ -199,7 +198,38 @@ class _BillingViewState extends State<BillingView> {
|
||||
],
|
||||
const PaymentMethodCard(),
|
||||
const SpendingBreakdownCard(),
|
||||
InvoiceHistorySection(invoices: state.invoiceHistory),
|
||||
if (state.invoiceHistory.isEmpty) _buildEmptyState(context)
|
||||
else InvoiceHistorySection(invoices: state.invoiceHistory),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildEmptyState(BuildContext context) {
|
||||
return Center(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: <Widget>[
|
||||
const SizedBox(height: UiConstants.space12),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(UiConstants.space6),
|
||||
decoration: BoxDecoration(
|
||||
color: UiColors.bgPopup,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: UiColors.border),
|
||||
),
|
||||
child: const Icon(
|
||||
UiIcons.file,
|
||||
size: 48,
|
||||
color: UiColors.textSecondary,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: UiConstants.space4),
|
||||
Text(
|
||||
'No Invoices for the selected period',
|
||||
style: UiTypography.body1m.textSecondary,
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
|
||||
@@ -24,9 +24,11 @@ class _PaymentMethodCardState extends State<PaymentMethodCard> {
|
||||
return null;
|
||||
}
|
||||
|
||||
final fdc.QueryResult<dc.GetAccountsByOwnerIdData,
|
||||
dc.GetAccountsByOwnerIdVariables> result =
|
||||
await dc.ExampleConnector.instance
|
||||
final fdc.QueryResult<
|
||||
dc.GetAccountsByOwnerIdData,
|
||||
dc.GetAccountsByOwnerIdVariables
|
||||
>
|
||||
result = await dc.ExampleConnector.instance
|
||||
.getAccountsByOwnerId(ownerId: businessId)
|
||||
.execute();
|
||||
return result.data;
|
||||
@@ -36,19 +38,29 @@ class _PaymentMethodCardState extends State<PaymentMethodCard> {
|
||||
Widget build(BuildContext context) {
|
||||
return FutureBuilder<dc.GetAccountsByOwnerIdData?>(
|
||||
future: _accountsFuture,
|
||||
builder: (BuildContext context,
|
||||
AsyncSnapshot<dc.GetAccountsByOwnerIdData?> snapshot) {
|
||||
builder:
|
||||
(
|
||||
BuildContext context,
|
||||
AsyncSnapshot<dc.GetAccountsByOwnerIdData?> snapshot,
|
||||
) {
|
||||
final List<dc.GetAccountsByOwnerIdAccounts> accounts =
|
||||
snapshot.data?.accounts ??
|
||||
<dc.GetAccountsByOwnerIdAccounts>[];
|
||||
final dc.GetAccountsByOwnerIdAccounts? account =
|
||||
accounts.isNotEmpty ? accounts.first : null;
|
||||
final String bankLabel =
|
||||
account?.bank.isNotEmpty == true ? account!.bank : '----';
|
||||
final String last4 =
|
||||
account?.last4.isNotEmpty == true ? account!.last4 : '----';
|
||||
final bool isPrimary = account?.isPrimary ?? false;
|
||||
final String expiryLabel = _formatExpiry(account?.expiryTime);
|
||||
snapshot.data?.accounts ?? <dc.GetAccountsByOwnerIdAccounts>[];
|
||||
final dc.GetAccountsByOwnerIdAccounts? account = accounts.isNotEmpty
|
||||
? accounts.first
|
||||
: null;
|
||||
|
||||
if (account == null) {
|
||||
return const SizedBox.shrink();
|
||||
}
|
||||
|
||||
final String bankLabel = account.bank.isNotEmpty == true
|
||||
? account.bank
|
||||
: '----';
|
||||
final String last4 = account.last4.isNotEmpty == true
|
||||
? account.last4
|
||||
: '----';
|
||||
final bool isPrimary = account.isPrimary ?? false;
|
||||
final String expiryLabel = _formatExpiry(account.expiryTime);
|
||||
|
||||
return Container(
|
||||
padding: const EdgeInsets.all(UiConstants.space4),
|
||||
@@ -76,7 +88,6 @@ class _PaymentMethodCardState extends State<PaymentMethodCard> {
|
||||
const SizedBox.shrink(),
|
||||
],
|
||||
),
|
||||
if (account != null) ...<Widget>[
|
||||
const SizedBox(height: UiConstants.space3),
|
||||
Container(
|
||||
padding: const EdgeInsets.all(UiConstants.space3),
|
||||
@@ -141,7 +152,6 @@ class _PaymentMethodCardState extends State<PaymentMethodCard> {
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
|
||||
Reference in New Issue
Block a user