Files
ingtrakapp/lib/screens/label_transactions_screen.dart
T
2026-09-09 14:38:17 +02:00

99 lines
3.5 KiB
Dart

/// Transactions that share a given label.
library;
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import '../models/transaction_meta.dart';
import '../providers/bank_provider.dart';
import '../providers/tx_meta_provider.dart';
import '../utils/app_theme.dart';
import '../utils/helpers.dart';
import '../widgets/responsive_body.dart';
import '../widgets/skip_build_when_covered.dart';
import 'transaction_detail_screen.dart';
class LabelTransactionsScreen extends StatelessWidget {
const LabelTransactionsScreen({super.key, required this.label});
final TxLabel label;
@override
Widget build(BuildContext context) {
final bank = context.watch<BankController>();
final meta = context.watch<TxMetaController>();
return Scaffold(
appBar: AppBar(
title: Text(label.name),
),
body: ResponsiveBody(
child: SkipBuildWhenCovered(
builder: (context) {
final txs = [
for (final tx in bank.transactions)
if (meta.labelIdsFor(tx).contains(label.id)) tx,
];
final theme = Theme.of(context);
final currency = bank.balance?.currency ??
(txs.isNotEmpty ? txs.first.currency : 'EUR');
var totalOut = 0.0;
for (final tx in txs) {
if (tx.amount < 0) totalOut += tx.amount.abs();
}
return ListView(
padding: const EdgeInsets.only(top: 8, bottom: 32),
children: [
ListTile(
contentPadding: EdgeInsets.zero,
leading: Icon(label.icon, color: label.color),
title: Text('${txs.length} transactions'),
subtitle:
Text('Money out ${formatMoney(totalOut, currency)}'),
),
const Divider(),
if (txs.isEmpty)
Padding(
padding: const EdgeInsets.symmetric(vertical: 32),
child: Text(
'No transactions with this label.',
textAlign: TextAlign.center,
style: theme.textTheme.bodyMedium,
),
)
else
for (final tx in txs)
ListTile(
contentPadding: EdgeInsets.zero,
title: Text(
tx.description,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
subtitle: Text(formatIsoDate(tx.date)),
trailing: Text(
formatMoney(tx.amount, tx.currency),
style: theme.textTheme.titleSmall?.copyWith(
color: tx.amount >= 0
? AppTheme.accent
: AppTheme.expense,
),
),
onTap: () {
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) =>
TransactionDetailScreen(tx: tx),
),
);
},
),
],
);
},
),
),
);
}
}