nice overview working
This commit is contained in:
@@ -12,6 +12,7 @@ import '../utils/navigation.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/loading_view.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
import '../widgets/skip_build_when_covered.dart';
|
||||
import 'transaction_detail_screen.dart';
|
||||
import 'transactions_screen.dart';
|
||||
|
||||
@@ -54,6 +55,10 @@ class _HomeBody extends StatelessWidget {
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
// Stay subscribed, but skip heavy scans while covered by another route
|
||||
// (e.g. transaction detail applying labels to many similar txs).
|
||||
context.watch<TxMetaController>();
|
||||
|
||||
if (bank.isLoading && bank.balance == null && !bank.hasData) {
|
||||
return const LoadingView(message: 'Checking bank link…');
|
||||
}
|
||||
@@ -89,16 +94,17 @@ class _HomeBody extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
final balance = bank.balance;
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final meta = context.watch<TxMetaController>();
|
||||
final recent = bank.transactions.take(5).toList(growable: false);
|
||||
final categorized = bank.transactions
|
||||
.where((tx) => meta.metaFor(tx).hasLabel)
|
||||
.length;
|
||||
return SkipBuildWhenCovered(
|
||||
builder: (context) {
|
||||
final balance = bank.balance;
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final meta = context.watch<TxMetaController>();
|
||||
final recent = bank.transactions.take(5).toList(growable: false);
|
||||
final categorized =
|
||||
meta.labeledTransactionCount(bank.transactions);
|
||||
|
||||
return ListView(
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
@@ -209,7 +215,7 @@ class _HomeBody extends StatelessWidget {
|
||||
leading: Builder(
|
||||
builder: (context) {
|
||||
final labels =
|
||||
meta.labelsFor(meta.metaFor(tx));
|
||||
meta.leafLabelsFor(meta.metaFor(tx));
|
||||
final label = labels.isEmpty ? null : labels.first;
|
||||
return Icon(
|
||||
label?.icon ?? Icons.receipt_long_outlined,
|
||||
@@ -247,6 +253,8 @@ class _HomeBody extends StatelessWidget {
|
||||
],
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../providers/bank_provider.dart';
|
||||
import '../providers/tx_meta_provider.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 {
|
||||
@@ -20,69 +21,77 @@ class LabelTransactionsScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
final bank = context.watch<BankController>();
|
||||
final meta = context.watch<TxMetaController>();
|
||||
final txs = [
|
||||
for (final tx in bank.transactions)
|
||||
if (meta.metaFor(tx).labelIds.contains(label.id)) tx,
|
||||
];
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
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 Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(label.name),
|
||||
),
|
||||
body: ResponsiveBody(
|
||||
child: 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,
|
||||
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 colors = theme.colorScheme;
|
||||
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)}'),
|
||||
),
|
||||
subtitle: Text(formatIsoDate(tx.date)),
|
||||
trailing: Text(
|
||||
formatMoney(tx.amount, tx.currency),
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: tx.amount >= 0 ? colors.primary : colors.error,
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => TransactionDetailScreen(tx: tx),
|
||||
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
|
||||
? colors.primary
|
||||
: colors.error,
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) =>
|
||||
TransactionDetailScreen(tx: tx),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,201 @@
|
||||
/// Manage labels: create, nest, and delete.
|
||||
library;
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../models/transaction_meta.dart';
|
||||
import '../providers/tx_meta_provider.dart';
|
||||
import '../widgets/label_parent_picker.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
|
||||
class LabelsScreen extends StatelessWidget {
|
||||
const LabelsScreen({super.key});
|
||||
|
||||
Future<void> _create(
|
||||
BuildContext context, {
|
||||
String? parentId,
|
||||
}) async {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final result = await showCreateLabelDialog(
|
||||
context,
|
||||
parents: meta.allLabels,
|
||||
initialParentId: parentId,
|
||||
);
|
||||
if (result == null || !context.mounted) return;
|
||||
await meta.createLabel(result.name, parentId: result.parentId);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Created “${result.name}”')),
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _delete(BuildContext context, TxLabel label) async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
builder: (dialogContext) {
|
||||
return AlertDialog(
|
||||
title: Text('Remove “${label.name}”?'),
|
||||
content: const Text(
|
||||
'This deletes the label. Transactions keep any other labels. '
|
||||
'Sub-labels move up one level.',
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, false),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.pop(dialogContext, true),
|
||||
child: const Text('Remove'),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
if (ok != true || !context.mounted) return;
|
||||
await context.read<TxMetaController>().removeLabel(label.id);
|
||||
if (!context.mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Removed “${label.name}”')),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final meta = context.watch<TxMetaController>();
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final entries = meta.labelsInTreeOrder();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Labels'),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'New label',
|
||||
onPressed: () => _create(context),
|
||||
icon: const Icon(Icons.add),
|
||||
),
|
||||
],
|
||||
),
|
||||
floatingActionButton: FloatingActionButton.extended(
|
||||
onPressed: () => _create(context),
|
||||
icon: const Icon(Icons.add),
|
||||
label: const Text('New label'),
|
||||
),
|
||||
body: ResponsiveBody(
|
||||
child: entries.isEmpty
|
||||
? ListView(
|
||||
children: [
|
||||
const SizedBox(height: 48),
|
||||
Icon(
|
||||
Icons.label_outline,
|
||||
size: 48,
|
||||
color: colors.outline,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Text(
|
||||
'No labels yet',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Create labels to categorize spending.',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
],
|
||||
)
|
||||
: ListView.separated(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 88),
|
||||
itemCount: entries.length + 1,
|
||||
separatorBuilder: (_, _) => const Divider(height: 1),
|
||||
itemBuilder: (context, index) {
|
||||
if (index == 0) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.fromLTRB(4, 4, 4, 12),
|
||||
child: Text(
|
||||
'Create, nest under another label, or delete custom '
|
||||
'ones. Built-in labels can be moved but not deleted.',
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
);
|
||||
}
|
||||
final entry = entries[index - 1];
|
||||
final label = entry.label;
|
||||
final parentId = meta.parentIdOf(label.id);
|
||||
final parent = parentId == null ? null : meta.labelById(parentId);
|
||||
return ListTile(
|
||||
contentPadding: EdgeInsets.fromLTRB(
|
||||
8 + entry.depth * 16.0,
|
||||
0,
|
||||
4,
|
||||
0,
|
||||
),
|
||||
leading: Icon(label.icon, color: label.color),
|
||||
title: Text(label.name),
|
||||
subtitle: Text(
|
||||
[
|
||||
if (label.custom) 'Custom' else 'Built-in',
|
||||
if (parent != null) 'under ${parent.name}',
|
||||
].join(' · '),
|
||||
),
|
||||
trailing: PopupMenuButton<String>(
|
||||
tooltip: 'Actions',
|
||||
onSelected: (value) async {
|
||||
switch (value) {
|
||||
case 'sub':
|
||||
await _create(context, parentId: label.id);
|
||||
case 'move':
|
||||
await showMoveLabelDialog(context, label: label);
|
||||
case 'delete':
|
||||
await _delete(context, label);
|
||||
}
|
||||
},
|
||||
itemBuilder: (context) => [
|
||||
if (meta.depthOf(label.id) < kMaxLabelDepth)
|
||||
const PopupMenuItem(
|
||||
value: 'sub',
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(Icons.subdirectory_arrow_right),
|
||||
title: Text('Add sub-label'),
|
||||
),
|
||||
),
|
||||
const PopupMenuItem(
|
||||
value: 'move',
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(Icons.account_tree_outlined),
|
||||
title: Text('Move under…'),
|
||||
),
|
||||
),
|
||||
if (label.custom)
|
||||
PopupMenuItem(
|
||||
value: 'delete',
|
||||
child: ListTile(
|
||||
dense: true,
|
||||
contentPadding: EdgeInsets.zero,
|
||||
leading: Icon(
|
||||
Icons.delete_outline,
|
||||
color: colors.error,
|
||||
),
|
||||
title: Text(
|
||||
'Delete',
|
||||
style: TextStyle(color: colors.error),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
+1165
-270
File diff suppressed because it is too large
Load Diff
@@ -13,6 +13,7 @@ import '../utils/connect_bank.dart';
|
||||
import '../utils/constants.dart';
|
||||
import '../utils/helpers.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
import 'labels_screen.dart';
|
||||
|
||||
class SettingsScreen extends StatelessWidget {
|
||||
const SettingsScreen({super.key});
|
||||
@@ -201,6 +202,24 @@ class SettingsScreen extends StatelessWidget {
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
Text('Labels', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
Card(
|
||||
child: ListTile(
|
||||
leading: const Icon(Icons.label_outline),
|
||||
title: const Text('Manage labels'),
|
||||
subtitle: const Text('Create, nest, move, or delete'),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: () {
|
||||
Navigator.of(context).push(
|
||||
MaterialPageRoute<void>(
|
||||
builder: (_) => const LabelsScreen(),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 28),
|
||||
Text('CSV import', style: theme.textTheme.titleMedium),
|
||||
const SizedBox(height: 8),
|
||||
Card(
|
||||
|
||||
@@ -9,6 +9,7 @@ import '../models/transaction_meta.dart';
|
||||
import '../providers/bank_provider.dart';
|
||||
import '../providers/tx_meta_provider.dart';
|
||||
import '../utils/helpers.dart';
|
||||
import '../widgets/label_parent_picker.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
|
||||
class TransactionDetailScreen extends StatefulWidget {
|
||||
@@ -23,8 +24,11 @@ class TransactionDetailScreen extends StatefulWidget {
|
||||
|
||||
class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
late final TextEditingController _notesController;
|
||||
late final TextEditingController _patternController;
|
||||
var _dirty = false;
|
||||
late bool _applyToSimilar;
|
||||
var _busy = false;
|
||||
String? _busyMessage;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -32,8 +36,14 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final notes = meta.metaFor(widget.tx).notes;
|
||||
_notesController = TextEditingController(text: notes);
|
||||
final pattern = defaultSimilarPattern(widget.tx.description);
|
||||
_patternController = TextEditingController(text: pattern);
|
||||
final all = context.read<BankController>().transactions;
|
||||
final similarCount = meta.countSimilar(widget.tx, all);
|
||||
final similarCount = meta.countSimilar(
|
||||
widget.tx,
|
||||
all,
|
||||
pattern: pattern,
|
||||
);
|
||||
// Default on when there are peers — otherwise users never notice the toggle.
|
||||
_applyToSimilar = similarCount > 1;
|
||||
}
|
||||
@@ -41,77 +51,165 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
@override
|
||||
void dispose() {
|
||||
_notesController.dispose();
|
||||
_patternController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
String get _pattern => _patternController.text.trim();
|
||||
|
||||
List<BankTransaction> _similarScope(TxMetaController meta) {
|
||||
final all = context.read<BankController>().transactions;
|
||||
if (!_applyToSimilar) return const [];
|
||||
return meta.similarTo(widget.tx, all);
|
||||
return meta.similarTo(widget.tx, all, pattern: _pattern);
|
||||
}
|
||||
|
||||
Future<void> _runBusy(
|
||||
Future<void> Function() action, {
|
||||
String? message,
|
||||
}) async {
|
||||
if (_busy) return;
|
||||
setState(() {
|
||||
_busy = true;
|
||||
_busyMessage = message;
|
||||
});
|
||||
// Let the progress bar paint before heavy similar-matching / rebuilds.
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
try {
|
||||
await action();
|
||||
} finally {
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_busy = false;
|
||||
_busyMessage = null;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _saveNotes() async {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final similar = _similarScope(meta);
|
||||
await meta.setNotes(
|
||||
widget.tx,
|
||||
_notesController.text,
|
||||
applyToSimilar: similar,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _dirty = false);
|
||||
final count = similar.isEmpty ? 1 : similar.length;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
count == 1
|
||||
? 'Notes saved'
|
||||
: 'Notes saved on $count similar transactions',
|
||||
),
|
||||
),
|
||||
await _runBusy(
|
||||
() async {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final similar = _similarScope(meta);
|
||||
final count = similar.isEmpty ? 1 : similar.length;
|
||||
await meta.setNotes(
|
||||
widget.tx,
|
||||
_notesController.text,
|
||||
applyToSimilar: similar,
|
||||
matchPattern: _pattern,
|
||||
);
|
||||
if (!mounted) return;
|
||||
setState(() => _dirty = false);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(
|
||||
count == 1
|
||||
? 'Notes saved'
|
||||
: 'Notes saved on $count similar transactions',
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
message: _applyToSimilar
|
||||
? 'Saving notes on matching transactions…'
|
||||
: 'Saving notes…',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _toggleLabel(String labelId) async {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final similar = _similarScope(meta);
|
||||
await meta.toggleLabel(
|
||||
widget.tx,
|
||||
labelId,
|
||||
applyToSimilar: similar,
|
||||
await _runBusy(
|
||||
() async {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final similar = _similarScope(meta);
|
||||
final count = similar.isEmpty ? 1 : similar.length;
|
||||
await meta.toggleLabel(
|
||||
widget.tx,
|
||||
labelId,
|
||||
applyToSimilar: similar,
|
||||
matchPattern: _pattern,
|
||||
);
|
||||
if (!mounted) return;
|
||||
if (count > 1) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Labels updated on $count similar transactions'),
|
||||
),
|
||||
);
|
||||
}
|
||||
},
|
||||
message: _applyToSimilar
|
||||
? 'Updating labels on matching transactions…'
|
||||
: null,
|
||||
);
|
||||
if (!mounted) return;
|
||||
final count = similar.isEmpty ? 1 : similar.length;
|
||||
if (count > 1) {
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text('Labels updated on $count similar transactions'),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _clearLabels() async {
|
||||
final meta = context.read<TxMetaController>();
|
||||
final similar = _similarScope(meta);
|
||||
await meta.clearLabels(
|
||||
widget.tx,
|
||||
applyToSimilar: similar,
|
||||
await _runBusy(
|
||||
() {
|
||||
final meta = context.read<TxMetaController>();
|
||||
return meta.clearLabels(
|
||||
widget.tx,
|
||||
applyToSimilar: _similarScope(meta),
|
||||
matchPattern: _pattern,
|
||||
);
|
||||
},
|
||||
message: _applyToSimilar
|
||||
? 'Clearing labels on matching transactions…'
|
||||
: 'Clearing labels…',
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _createLabel() async {
|
||||
final name = await showDialog<String>(
|
||||
context: context,
|
||||
builder: (context) => const _NewLabelDialog(),
|
||||
);
|
||||
if (name == null || name.isEmpty || !mounted) return;
|
||||
final meta = context.read<TxMetaController>();
|
||||
final label = await meta.createLabel(name);
|
||||
final result = await showCreateLabelDialog(
|
||||
context,
|
||||
parents: meta.allLabels,
|
||||
);
|
||||
if (result == null || !mounted) return;
|
||||
final label = await meta.createLabel(
|
||||
result.name,
|
||||
parentId: result.parentId,
|
||||
);
|
||||
if (!mounted) return;
|
||||
await _toggleLabel(label.id);
|
||||
}
|
||||
|
||||
Future<void> _labelActions(TxLabel label) async {
|
||||
final action = await showModalBottomSheet<String>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
builder: (sheetContext) {
|
||||
return SafeArea(
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
ListTile(
|
||||
leading: const Icon(Icons.account_tree_outlined),
|
||||
title: const Text('Move under…'),
|
||||
onTap: () => Navigator.pop(sheetContext, 'move'),
|
||||
),
|
||||
if (label.custom)
|
||||
ListTile(
|
||||
leading: Icon(
|
||||
Icons.delete_outline,
|
||||
color: Theme.of(sheetContext).colorScheme.error,
|
||||
),
|
||||
title: const Text('Remove label'),
|
||||
onTap: () => Navigator.pop(sheetContext, 'remove'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
if (!mounted || action == null) return;
|
||||
if (action == 'move') {
|
||||
await showMoveLabelDialog(context, label: label);
|
||||
} else if (action == 'remove') {
|
||||
await _confirmRemoveLabel(label);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> _confirmRemoveLabel(TxLabel label) async {
|
||||
final ok = await showDialog<bool>(
|
||||
context: context,
|
||||
@@ -143,17 +241,18 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
final tx = widget.tx;
|
||||
final metaController = context.watch<TxMetaController>();
|
||||
final meta = metaController.metaFor(tx);
|
||||
final all = context.watch<BankController>().transactions;
|
||||
final similarCount = metaController.countSimilar(tx, all);
|
||||
// Prefer read: bank data rarely changes while editing labels.
|
||||
final all = context.read<BankController>().transactions;
|
||||
final similarCount = metaController.countSimilar(
|
||||
tx,
|
||||
all,
|
||||
pattern: _pattern,
|
||||
);
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final amountColor = tx.amount >= 0 ? colors.primary : colors.error;
|
||||
final selectedIds = meta.labelIds.toSet();
|
||||
final merchantPreview = tx.merchantKey.isEmpty
|
||||
? tx.description
|
||||
: (tx.merchantKey.length > 48
|
||||
? '${tx.merchantKey.substring(0, 47)}…'
|
||||
: tx.merchantKey);
|
||||
final labelEntries = metaController.labelsInTreeOrder();
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -161,7 +260,7 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
actions: [
|
||||
if (_dirty)
|
||||
TextButton(
|
||||
onPressed: _saveNotes,
|
||||
onPressed: _busy ? null : _saveNotes,
|
||||
child: const Text('Save'),
|
||||
),
|
||||
],
|
||||
@@ -170,9 +269,29 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
child: ListView(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 32),
|
||||
children: [
|
||||
if (_busy) ...[
|
||||
const LinearProgressIndicator(minHeight: 2),
|
||||
if (_busyMessage != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 8, 0, 4),
|
||||
child: Text(
|
||||
_busyMessage!,
|
||||
style: theme.textTheme.labelMedium?.copyWith(
|
||||
color: colors.primary,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
AbsorbPointer(
|
||||
absorbing: _busy,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
formatMoney(tx.amount, tx.currency),
|
||||
style: theme.textTheme.headlineMedium?.copyWith(color: amountColor),
|
||||
style: theme.textTheme.headlineMedium?.copyWith(
|
||||
color: amountColor,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Text(tx.description, style: theme.textTheme.titleMedium),
|
||||
@@ -184,19 +303,47 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
].join(' · '),
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
if (similarCount > 1) ...[
|
||||
const SizedBox(height: 16),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
secondary: const Icon(Icons.copy_all_outlined),
|
||||
title: const Text('Apply to all similar'),
|
||||
subtitle: Text(
|
||||
'$similarCount matches · $merchantPreview',
|
||||
const SizedBox(height: 16),
|
||||
Text('Match similar', style: theme.textTheme.titleSmall),
|
||||
const SizedBox(height: 8),
|
||||
TextField(
|
||||
controller: _patternController,
|
||||
textInputAction: TextInputAction.done,
|
||||
enabled: !_busy,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'e.g. albert heijn or /albert\\s*heijn/',
|
||||
helperText:
|
||||
'Plain text = contains. Wrap with /…/ for regex.',
|
||||
helperMaxLines: 2,
|
||||
suffixIcon: IconButton(
|
||||
tooltip: 'Reset default',
|
||||
onPressed: _busy
|
||||
? null
|
||||
: () {
|
||||
setState(() {
|
||||
_patternController.text =
|
||||
defaultSimilarPattern(tx.description);
|
||||
});
|
||||
},
|
||||
icon: const Icon(Icons.refresh),
|
||||
),
|
||||
value: _applyToSimilar,
|
||||
onChanged: (value) => setState(() => _applyToSimilar = value),
|
||||
),
|
||||
],
|
||||
onChanged: (_) => setState(() {}),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
secondary: const Icon(Icons.copy_all_outlined),
|
||||
title: const Text('Apply to all similar'),
|
||||
subtitle: Text(
|
||||
similarCount <= 1
|
||||
? 'No other matches for this pattern'
|
||||
: '$similarCount matching transactions',
|
||||
),
|
||||
value: _applyToSimilar && similarCount > 1,
|
||||
onChanged: _busy || similarCount <= 1
|
||||
? null
|
||||
: (value) => setState(() => _applyToSimilar = value),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
@@ -204,45 +351,104 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
title: const Text('Recurring'),
|
||||
subtitle: const Text('Salary, mortgage, subscriptions…'),
|
||||
value: meta.recurring,
|
||||
onChanged: (value) {
|
||||
context.read<TxMetaController>().setRecurring(tx, value);
|
||||
},
|
||||
onChanged: _busy
|
||||
? null
|
||||
: (value) {
|
||||
context.read<TxMetaController>().setRecurring(tx, value);
|
||||
},
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Row(
|
||||
children: [
|
||||
Text('Labels', style: theme.textTheme.titleSmall),
|
||||
const Spacer(),
|
||||
TextButton(
|
||||
onPressed: _busy ? null : _createLabel,
|
||||
child: const Text('New'),
|
||||
),
|
||||
if (meta.hasLabel)
|
||||
TextButton(
|
||||
onPressed: _clearLabels,
|
||||
onPressed: _busy ? null : _clearLabels,
|
||||
child: const Text('Clear'),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final label in metaController.allLabels)
|
||||
GestureDetector(
|
||||
onLongPress: label.custom
|
||||
? () => _confirmRemoveLabel(label)
|
||||
: null,
|
||||
child: FilterChip(
|
||||
avatar: Icon(label.icon, size: 16, color: label.color),
|
||||
label: Text(label.name),
|
||||
selected: selectedIds.contains(label.id),
|
||||
onSelected: (_) => _toggleLabel(label.id),
|
||||
),
|
||||
),
|
||||
ActionChip(
|
||||
avatar: const Icon(Icons.add, size: 16),
|
||||
label: const Text('New label'),
|
||||
onPressed: _createLabel,
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: colors.surfaceContainerHighest,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
border: Border.all(
|
||||
color: colors.outlineVariant.withValues(alpha: 0.8),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: ClipRRect(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
child: Column(
|
||||
children: [
|
||||
for (final entry in labelEntries) ...[
|
||||
if (entry != labelEntries.first)
|
||||
Divider(
|
||||
height: 1,
|
||||
indent: 40,
|
||||
color: colors.outlineVariant.withValues(alpha: 0.45),
|
||||
),
|
||||
InkWell(
|
||||
onTap: _busy ? null : () => _toggleLabel(entry.label.id),
|
||||
onLongPress:
|
||||
_busy ? null : () => _labelActions(entry.label),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.fromLTRB(
|
||||
8 + entry.depth * 16.0,
|
||||
2,
|
||||
4,
|
||||
2,
|
||||
),
|
||||
child: Row(
|
||||
children: [
|
||||
if (entry.depth > 0) ...[
|
||||
Icon(
|
||||
Icons.subdirectory_arrow_right,
|
||||
size: 14,
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
],
|
||||
Icon(
|
||||
entry.label.icon,
|
||||
size: 18,
|
||||
color: entry.label.color,
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: Text(
|
||||
entry.label.name,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
maxLines: 1,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 32,
|
||||
width: 32,
|
||||
child: Checkbox(
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
visualDensity: VisualDensity.compact,
|
||||
value: selectedIds.contains(entry.label.id),
|
||||
onChanged: _busy
|
||||
? null
|
||||
: (_) => _toggleLabel(entry.label.id),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 24),
|
||||
Text('Notes', style: theme.textTheme.titleSmall),
|
||||
@@ -251,6 +457,7 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
controller: _notesController,
|
||||
minLines: 3,
|
||||
maxLines: 6,
|
||||
enabled: !_busy,
|
||||
textInputAction: TextInputAction.newline,
|
||||
decoration: const InputDecoration(
|
||||
hintText: 'Add a private note…',
|
||||
@@ -261,7 +468,7 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
FilledButton(
|
||||
onPressed: _dirty ? _saveNotes : null,
|
||||
onPressed: _dirty && !_busy ? _saveNotes : null,
|
||||
child: Text(
|
||||
_applyToSimilar && similarCount > 1
|
||||
? 'Save notes for $similarCount'
|
||||
@@ -270,10 +477,12 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
Text(
|
||||
'Tap labels to add or remove several. Long-press a custom label '
|
||||
'to delete it. Similar matches strip dates and ids so supermarket '
|
||||
'purchases group together.',
|
||||
'Sub-labels also select their parents. Unchecking a parent '
|
||||
'clears its sub-labels. Long-press a row to move or delete.',
|
||||
style: theme.textTheme.labelMedium,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -281,54 +490,3 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
class _NewLabelDialog extends StatefulWidget {
|
||||
const _NewLabelDialog();
|
||||
|
||||
@override
|
||||
State<_NewLabelDialog> createState() => _NewLabelDialogState();
|
||||
}
|
||||
|
||||
class _NewLabelDialogState extends State<_NewLabelDialog> {
|
||||
late final TextEditingController _controller;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_controller = TextEditingController();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_controller.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _submit() {
|
||||
Navigator.pop(context, _controller.text.trim());
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('New label'),
|
||||
content: TextField(
|
||||
controller: _controller,
|
||||
autofocus: true,
|
||||
textCapitalization: TextCapitalization.sentences,
|
||||
decoration: const InputDecoration(hintText: 'e.g. Supermarket'),
|
||||
onSubmitted: (_) => _submit(),
|
||||
),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.pop(context),
|
||||
child: const Text('Cancel'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: _submit,
|
||||
child: const Text('Create'),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
/// Searchable transaction list with month heatmap and money in/out totals.
|
||||
library;
|
||||
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
@@ -13,28 +15,53 @@ import '../utils/helpers.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../utils/tx_calendar.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/label_filter_dialog.dart';
|
||||
import '../widgets/loading_view.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
import '../widgets/skip_build_when_covered.dart';
|
||||
import '../widgets/tx_heatmap.dart';
|
||||
import 'transaction_detail_screen.dart';
|
||||
|
||||
class TransactionsScreen extends StatefulWidget {
|
||||
const TransactionsScreen({super.key, this.initialMonth});
|
||||
const TransactionsScreen({
|
||||
super.key,
|
||||
this.initialMonth,
|
||||
this.initialLabelIds = const {},
|
||||
this.initialSearchInMonthOnly,
|
||||
this.initialYear,
|
||||
});
|
||||
|
||||
/// When set, opens on this calendar month instead of the current month.
|
||||
final DateTime? initialMonth;
|
||||
|
||||
/// Pre-select these label filters (e.g. from overview history).
|
||||
final Set<String> initialLabelIds;
|
||||
|
||||
/// When set, overrides the default "search in month" checkbox.
|
||||
final bool? initialSearchInMonthOnly;
|
||||
|
||||
/// When set, label/search results are limited to this calendar year.
|
||||
final int? initialYear;
|
||||
|
||||
@override
|
||||
State<TransactionsScreen> createState() => _TransactionsScreenState();
|
||||
}
|
||||
|
||||
class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
static const _minLiveSearchChars = 3;
|
||||
static const _searchDebounce = Duration(milliseconds: 280);
|
||||
|
||||
final _searchController = TextEditingController();
|
||||
String _query = '';
|
||||
late DateTime _month;
|
||||
DateTime? _selectedDay;
|
||||
var _searchInMonthOnly = false;
|
||||
final Set<String> _labelFilters = {};
|
||||
late bool _searchInMonthOnly;
|
||||
late final Set<String> _labelFilters;
|
||||
int? _yearFilter;
|
||||
var _showCalendar = false;
|
||||
|
||||
/// Query actually used for filtering (Enter, or live once ≥3 chars).
|
||||
String _activeQuery = '';
|
||||
Timer? _searchDebounceTimer;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@@ -47,16 +74,20 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
final start = monthStart(initial);
|
||||
_month = start.isAfter(now) ? now : start;
|
||||
}
|
||||
_labelFilters = Set<String>.of(widget.initialLabelIds);
|
||||
_searchInMonthOnly = widget.initialSearchInMonthOnly ?? false;
|
||||
_yearFilter = widget.initialYear;
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_searchDebounceTimer?.cancel();
|
||||
_searchController.dispose();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
bool get _isSearching =>
|
||||
_query.trim().isNotEmpty || _labelFilters.isNotEmpty;
|
||||
_activeQuery.trim().isNotEmpty || _labelFilters.isNotEmpty;
|
||||
|
||||
void _goMonth(int delta) {
|
||||
final next = addMonths(_month, delta);
|
||||
@@ -70,17 +101,44 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
|
||||
DateTime? _txDate(BankTransaction tx) => DateTime.tryParse(tx.date);
|
||||
|
||||
bool _inCalendarScope(BankTransaction tx) {
|
||||
final date = _txDate(tx);
|
||||
if (date == null) return false;
|
||||
if (_selectedDay != null) return isSameDay(date, _selectedDay!);
|
||||
return isSameMonth(date, _month);
|
||||
List<BankTransaction> _yearScoped(List<BankTransaction> all) {
|
||||
final year = _yearFilter;
|
||||
if (year == null) return all;
|
||||
return [
|
||||
for (final tx in all)
|
||||
if (_txDate(tx)?.year == year) tx,
|
||||
];
|
||||
}
|
||||
|
||||
bool _inMonth(BankTransaction tx) {
|
||||
final date = _txDate(tx);
|
||||
if (date == null) return false;
|
||||
return isSameMonth(date, _month);
|
||||
void _onSearchChanged(String value) {
|
||||
final trimmed = value.trim();
|
||||
_searchDebounceTimer?.cancel();
|
||||
|
||||
if (trimmed.length >= _minLiveSearchChars) {
|
||||
// TextField updates via the controller; only rebuild the list after debounce.
|
||||
_searchDebounceTimer = Timer(_searchDebounce, () {
|
||||
if (!mounted) return;
|
||||
if (_activeQuery == trimmed) return;
|
||||
setState(() => _activeQuery = trimmed);
|
||||
});
|
||||
return;
|
||||
}
|
||||
|
||||
// Below threshold: no live search. Clear active text filter if needed.
|
||||
if (_activeQuery.isNotEmpty) {
|
||||
setState(() => _activeQuery = '');
|
||||
}
|
||||
}
|
||||
|
||||
void _onSearchSubmitted(String value) {
|
||||
_searchDebounceTimer?.cancel();
|
||||
setState(() => _activeQuery = value.trim());
|
||||
}
|
||||
|
||||
void _clearSearch() {
|
||||
_searchDebounceTimer?.cancel();
|
||||
_searchController.clear();
|
||||
setState(() => _activeQuery = '');
|
||||
}
|
||||
|
||||
Future<void> _pickLabels(List<TxLabel> available) async {
|
||||
@@ -91,70 +149,21 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
return;
|
||||
}
|
||||
|
||||
final selected = Set<String>.of(_labelFilters);
|
||||
await showModalBottomSheet<void>(
|
||||
context: context,
|
||||
showDragHandle: true,
|
||||
builder: (sheetContext) {
|
||||
return StatefulBuilder(
|
||||
builder: (context, setSheetState) {
|
||||
return SafeArea(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 24),
|
||||
child: Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
Text(
|
||||
'Filter by label',
|
||||
style: Theme.of(context).textTheme.titleMedium,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
children: [
|
||||
for (final label in available)
|
||||
FilterChip(
|
||||
avatar: Icon(
|
||||
label.icon,
|
||||
size: 16,
|
||||
color: label.color,
|
||||
),
|
||||
label: Text(label.name),
|
||||
selected: selected.contains(label.id),
|
||||
onSelected: (value) {
|
||||
setSheetState(() {
|
||||
if (value) {
|
||||
selected.add(label.id);
|
||||
} else {
|
||||
selected.remove(label.id);
|
||||
}
|
||||
});
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 16),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_labelFilters
|
||||
..clear()
|
||||
..addAll(selected);
|
||||
});
|
||||
Navigator.pop(sheetContext);
|
||||
},
|
||||
child: const Text('Apply'),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
},
|
||||
final result = await showLabelFilterDialog(
|
||||
context,
|
||||
available: available,
|
||||
initiallySelected: Set<String>.of(_labelFilters),
|
||||
title: 'Filter transactions',
|
||||
subtitle: 'Show transactions with any of these labels.',
|
||||
includeUncategorized: true,
|
||||
);
|
||||
if (result == null || !mounted) return;
|
||||
|
||||
setState(() {
|
||||
_labelFilters
|
||||
..clear()
|
||||
..addAll(result);
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -170,11 +179,21 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
refreshing: bank.isLoading,
|
||||
),
|
||||
),
|
||||
body: RefreshIndicator(
|
||||
onRefresh: bank.refresh,
|
||||
child: ResponsiveBody(
|
||||
child: _buildBody(context, bank),
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
if (bank.isLoading && bank.transactions.isNotEmpty)
|
||||
const LinearProgressIndicator(minHeight: 2),
|
||||
Expanded(
|
||||
child: RefreshIndicator(
|
||||
onRefresh: bank.refresh,
|
||||
child: ResponsiveBody(
|
||||
child: SkipBuildWhenCovered(
|
||||
builder: (context) => _buildBody(context, bank),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -183,12 +202,13 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
final metaController = context.watch<TxMetaController>();
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
final txs = bank.transactions;
|
||||
|
||||
if (bank.isLoading && bank.transactions.isEmpty) {
|
||||
if (bank.isLoading && txs.isEmpty) {
|
||||
return const LoadingView(message: 'Loading transactions…');
|
||||
}
|
||||
|
||||
if (!bank.isLinked && bank.transactions.isEmpty) {
|
||||
if (!bank.isLinked && txs.isEmpty) {
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
@@ -204,7 +224,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
if (bank.error != null && bank.transactions.isEmpty) {
|
||||
if (bank.error != null && txs.isEmpty) {
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: [
|
||||
@@ -219,7 +239,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
if (bank.transactions.isEmpty) {
|
||||
if (txs.isEmpty) {
|
||||
return ListView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
children: const [
|
||||
@@ -233,33 +253,55 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
}
|
||||
|
||||
final nowMonth = monthStart(DateTime.now());
|
||||
final monthDates = <DateTime>[
|
||||
for (final tx in bank.transactions)
|
||||
if (_txDate(tx) != null && isSameMonth(_txDate(tx)!, _month))
|
||||
dateOnly(_txDate(tx)!),
|
||||
];
|
||||
final counts = txCountsByDay(monthDates);
|
||||
final monthDates = <DateTime>[];
|
||||
final calendarScoped = <BankTransaction>[];
|
||||
final monthScoped = <BankTransaction>[];
|
||||
|
||||
final calendarScoped = [
|
||||
for (final tx in bank.transactions)
|
||||
if (_inCalendarScope(tx)) tx,
|
||||
];
|
||||
for (final tx in txs) {
|
||||
final date = _txDate(tx);
|
||||
if (date == null) continue;
|
||||
if (isSameMonth(date, _month)) {
|
||||
monthDates.add(dateOnly(date));
|
||||
monthScoped.add(tx);
|
||||
if (_selectedDay == null || isSameDay(date, _selectedDay!)) {
|
||||
calendarScoped.add(tx);
|
||||
}
|
||||
} else if (_selectedDay != null && isSameDay(date, _selectedDay!)) {
|
||||
calendarScoped.add(tx);
|
||||
}
|
||||
}
|
||||
final counts = txCountsByDay(monthDates);
|
||||
|
||||
final searchPool = !_isSearching
|
||||
? calendarScoped
|
||||
: _searchInMonthOnly
|
||||
? [
|
||||
for (final tx in bank.transactions)
|
||||
if (_inMonth(tx)) tx,
|
||||
]
|
||||
: bank.transactions;
|
||||
? monthScoped
|
||||
: _yearScoped(txs);
|
||||
|
||||
// Text hits first (no label filter) so refine chips stay available while selecting.
|
||||
final textMatched = _activeQuery.trim().isEmpty
|
||||
? const <BankTransaction>[]
|
||||
: metaController.search(searchPool, _activeQuery);
|
||||
|
||||
final filtered = metaController.search(
|
||||
searchPool,
|
||||
_query,
|
||||
_activeQuery,
|
||||
labelIds: _labelFilters,
|
||||
);
|
||||
|
||||
final refineLabels = _activeQuery.trim().isEmpty
|
||||
? const <TxLabel>[]
|
||||
: metaController.usedLabels(textMatched);
|
||||
final showUncategorizedRefine = _activeQuery.trim().isNotEmpty &&
|
||||
textMatched.any((tx) => !metaController.metaFor(tx).hasLabel);
|
||||
final refineChoices = <TxLabel>[
|
||||
if (showUncategorizedRefine &&
|
||||
!_labelFilters.contains(kUncategorizedFilterId))
|
||||
kUncategorizedFilterLabel,
|
||||
for (final label in refineLabels)
|
||||
if (!_labelFilters.contains(label.id)) label,
|
||||
];
|
||||
|
||||
var moneyOut = 0.0;
|
||||
var moneyIn = 0.0;
|
||||
for (final tx in calendarScoped) {
|
||||
@@ -270,173 +312,371 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
}
|
||||
}
|
||||
final currency = bank.balance?.currency ??
|
||||
(bank.transactions.isNotEmpty
|
||||
? bank.transactions.first.currency
|
||||
: 'EUR');
|
||||
final usedLabels = metaController.usedLabels(bank.transactions);
|
||||
(txs.isNotEmpty ? txs.first.currency : 'EUR');
|
||||
final labelById = {
|
||||
for (final label in metaController.allLabels) label.id: label,
|
||||
};
|
||||
|
||||
return ListView(
|
||||
return CustomScrollView(
|
||||
physics: const AlwaysScrollableScrollPhysics(),
|
||||
padding: const EdgeInsets.only(bottom: 32),
|
||||
children: [
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: TextField(
|
||||
controller: _searchController,
|
||||
textInputAction: TextInputAction.search,
|
||||
decoration: InputDecoration(
|
||||
hintText: 'Search description, notes…',
|
||||
prefixIcon: IconButton(
|
||||
tooltip: 'Labels',
|
||||
onPressed: () => _pickLabels(usedLabels),
|
||||
icon: Icon(
|
||||
Icons.search,
|
||||
color: _labelFilters.isEmpty ? null : colors.primary,
|
||||
),
|
||||
),
|
||||
suffixIcon: _query.isEmpty
|
||||
? null
|
||||
: IconButton(
|
||||
tooltip: 'Clear',
|
||||
onPressed: () {
|
||||
_searchController.clear();
|
||||
setState(() => _query = '');
|
||||
},
|
||||
icon: const Icon(Icons.clear),
|
||||
),
|
||||
slivers: [
|
||||
if (bank.error != null && txs.isNotEmpty)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
||||
child: Material(
|
||||
color: colors.errorContainer,
|
||||
borderRadius: BorderRadius.circular(10),
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(
|
||||
horizontal: 12,
|
||||
vertical: 8,
|
||||
),
|
||||
onChanged: (value) => setState(() => _query = value),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Tooltip(
|
||||
message: 'Search only in calendar month',
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _searchInMonthOnly,
|
||||
onChanged: (value) {
|
||||
setState(() => _searchInMonthOnly = value ?? false);
|
||||
},
|
||||
child: Text(
|
||||
bank.error!,
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onErrorContainer,
|
||||
),
|
||||
Text('Month', style: theme.textTheme.labelMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_labelFilters.isNotEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Wrap(
|
||||
spacing: 8,
|
||||
runSpacing: 8,
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(top: 8, bottom: 4),
|
||||
child: Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
for (final id in _labelFilters)
|
||||
if (labelById[id] != null)
|
||||
InputChip(
|
||||
avatar: Icon(
|
||||
labelById[id]!.icon,
|
||||
size: 16,
|
||||
color: labelById[id]!.color,
|
||||
Expanded(
|
||||
child: ValueListenableBuilder<TextEditingValue>(
|
||||
valueListenable: _searchController,
|
||||
builder: (context, value, _) {
|
||||
final draft = value.text.trim();
|
||||
final showHint = draft.isNotEmpty &&
|
||||
draft.length < _minLiveSearchChars &&
|
||||
draft != _activeQuery.trim();
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: [
|
||||
TextField(
|
||||
controller: _searchController,
|
||||
textInputAction: TextInputAction.search,
|
||||
decoration: InputDecoration(
|
||||
hintText:
|
||||
'Search (3+ chars, or press search)',
|
||||
prefixIcon: const Icon(Icons.search),
|
||||
suffixIcon: value.text.isNotEmpty
|
||||
? IconButton(
|
||||
tooltip: 'Clear',
|
||||
onPressed: _clearSearch,
|
||||
icon: const Icon(Icons.clear),
|
||||
)
|
||||
: null,
|
||||
),
|
||||
onChanged: _onSearchChanged,
|
||||
onSubmitted: _onSearchSubmitted,
|
||||
),
|
||||
if (showHint)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(top: 6),
|
||||
child: Text(
|
||||
'Press search to look up short terms',
|
||||
style:
|
||||
theme.textTheme.labelMedium?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 2),
|
||||
IconButton(
|
||||
tooltip: _labelFilters.isEmpty
|
||||
? 'Filter by label'
|
||||
: 'Filter by label (${_labelFilters.length})',
|
||||
onPressed: () => _pickLabels(
|
||||
metaController.usedLabels(txs),
|
||||
),
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: _labelFilters.isEmpty
|
||||
? null
|
||||
: colors.secondaryContainer,
|
||||
),
|
||||
icon: Badge(
|
||||
isLabelVisible: _labelFilters.isNotEmpty,
|
||||
smallSize: 6,
|
||||
child: const Icon(Icons.filter_list),
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: _showCalendar ? 'Hide calendar' : 'Show calendar',
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_showCalendar = !_showCalendar;
|
||||
if (!_showCalendar) _selectedDay = null;
|
||||
});
|
||||
},
|
||||
style: IconButton.styleFrom(
|
||||
backgroundColor: _showCalendar
|
||||
? colors.secondaryContainer
|
||||
: null,
|
||||
),
|
||||
icon: Icon(
|
||||
_showCalendar
|
||||
? Icons.calendar_month
|
||||
: Icons.calendar_month_outlined,
|
||||
),
|
||||
),
|
||||
Tooltip(
|
||||
message: 'Search only in calendar month',
|
||||
child: Row(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
Checkbox(
|
||||
value: _searchInMonthOnly,
|
||||
onChanged: (value) {
|
||||
setState(
|
||||
() => _searchInMonthOnly = value ?? false,
|
||||
);
|
||||
},
|
||||
),
|
||||
label: Text(labelById[id]!.name),
|
||||
onDeleted: () {
|
||||
setState(() => _labelFilters.remove(id));
|
||||
},
|
||||
),
|
||||
Text('Month', style: theme.textTheme.labelMedium),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
TxHeatmap(
|
||||
month: _month,
|
||||
counts: counts,
|
||||
canGoForward: _month.isBefore(nowMonth),
|
||||
selectedDay: _selectedDay,
|
||||
onPreviousMonth: () => _goMonth(-1),
|
||||
onNextMonth: () => _goMonth(1),
|
||||
onSelectDay: (day) => setState(() => _selectedDay = day),
|
||||
),
|
||||
if (_selectedDay != null)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: InputChip(
|
||||
label: Text(formatDate(_selectedDay!)),
|
||||
onDeleted: () => setState(() => _selectedDay = null),
|
||||
if (_showCalendar) ...[
|
||||
SliverToBoxAdapter(
|
||||
child: TxHeatmap(
|
||||
month: _month,
|
||||
counts: counts,
|
||||
canGoForward: _month.isBefore(nowMonth),
|
||||
selectedDay: _selectedDay,
|
||||
onPreviousMonth: () => _goMonth(-1),
|
||||
onNextMonth: () => _goMonth(1),
|
||||
onSelectDay: (day) => setState(() => _selectedDay = day),
|
||||
),
|
||||
),
|
||||
if (_selectedDay != null)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: InputChip(
|
||||
label: Text(formatDate(_selectedDay!)),
|
||||
onDeleted: () => setState(() => _selectedDay = null),
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
] else
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 4, 0, 8),
|
||||
child: Row(
|
||||
children: [
|
||||
IconButton(
|
||||
tooltip: 'Previous month',
|
||||
onPressed: () => _goMonth(-1),
|
||||
icon: const Icon(Icons.chevron_left),
|
||||
),
|
||||
Expanded(
|
||||
child: Text(
|
||||
formatMonthYear(_month),
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
IconButton(
|
||||
tooltip: 'Next month',
|
||||
onPressed:
|
||||
_month.isBefore(nowMonth) ? () => _goMonth(1) : null,
|
||||
icon: const Icon(Icons.chevron_right),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 4, 0, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _TotalsCard(
|
||||
label: 'Money out',
|
||||
value: formatMoney(moneyOut, currency),
|
||||
color: colors.error,
|
||||
icon: Icons.arrow_upward,
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.fromLTRB(0, 4, 0, 12),
|
||||
child: Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _TotalsCard(
|
||||
label: 'Money out',
|
||||
value: formatMoney(moneyOut, currency),
|
||||
color: colors.error,
|
||||
icon: Icons.arrow_upward,
|
||||
),
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: _TotalsCard(
|
||||
label: 'Money in',
|
||||
value: formatMoney(moneyIn, currency),
|
||||
color: colors.primary,
|
||||
icon: Icons.arrow_downward,
|
||||
const SizedBox(width: 10),
|
||||
Expanded(
|
||||
child: _TotalsCard(
|
||||
label: 'Money in',
|
||||
value: formatMoney(moneyIn, currency),
|
||||
color: colors.primary,
|
||||
icon: Icons.arrow_downward,
|
||||
),
|
||||
),
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
if (_isSearching)
|
||||
Padding(
|
||||
if (_isSearching || _labelFilters.isNotEmpty)
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
if (_isSearching)
|
||||
Text(
|
||||
_yearFilter != null
|
||||
? 'Filtered to $_yearFilter'
|
||||
: _searchInMonthOnly
|
||||
? 'Searching in ${formatMonthYear(_month)}'
|
||||
: 'Searching all transactions',
|
||||
style: theme.textTheme.labelMedium,
|
||||
),
|
||||
if (_labelFilters.isNotEmpty) ...[
|
||||
if (_isSearching) const SizedBox(height: 8),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
for (final id in _labelFilters)
|
||||
if (id == kUncategorizedFilterId)
|
||||
InputChip(
|
||||
visualDensity: VisualDensity.compact,
|
||||
avatar: Icon(
|
||||
kUncategorizedFilterLabel.icon,
|
||||
size: 14,
|
||||
color: kUncategorizedFilterLabel.color,
|
||||
),
|
||||
label: const Text('Uncategorized'),
|
||||
onDeleted: () {
|
||||
setState(
|
||||
() => _labelFilters
|
||||
.remove(kUncategorizedFilterId),
|
||||
);
|
||||
},
|
||||
)
|
||||
else if (labelById[id] != null)
|
||||
InputChip(
|
||||
visualDensity: VisualDensity.compact,
|
||||
avatar: Icon(
|
||||
labelById[id]!.icon,
|
||||
size: 14,
|
||||
color: labelById[id]!.color,
|
||||
),
|
||||
label: Text(labelById[id]!.name),
|
||||
onDeleted: () {
|
||||
setState(() => _labelFilters.remove(id));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
if (refineChoices.isNotEmpty) ...[
|
||||
const SizedBox(height: 8),
|
||||
Text(
|
||||
'Refine by label',
|
||||
style: theme.textTheme.labelSmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 6),
|
||||
Wrap(
|
||||
spacing: 6,
|
||||
runSpacing: 6,
|
||||
children: [
|
||||
for (final label in refineChoices)
|
||||
FilterChip(
|
||||
visualDensity: VisualDensity.compact,
|
||||
materialTapTargetSize:
|
||||
MaterialTapTargetSize.shrinkWrap,
|
||||
avatar: Icon(
|
||||
label.icon,
|
||||
size: 14,
|
||||
color: label.color,
|
||||
),
|
||||
label: Text(label.name),
|
||||
selected: false,
|
||||
onSelected: (_) {
|
||||
setState(() => _labelFilters.add(label.id));
|
||||
},
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.only(bottom: 8),
|
||||
child: Text(
|
||||
_searchInMonthOnly
|
||||
? 'Searching in ${formatMonthYear(_month)}'
|
||||
: 'Searching all transactions',
|
||||
style: theme.textTheme.labelMedium,
|
||||
filtered.length == 1
|
||||
? '1 transaction'
|
||||
: '${filtered.length} transactions',
|
||||
style: theme.textTheme.titleSmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
),
|
||||
),
|
||||
if (filtered.isEmpty)
|
||||
Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Text(
|
||||
_isSearching
|
||||
? 'No transactions match this search.'
|
||||
: _selectedDay != null
|
||||
? 'No transactions on this day.'
|
||||
: 'No transactions this month.',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
SliverToBoxAdapter(
|
||||
child: Padding(
|
||||
padding: const EdgeInsets.symmetric(vertical: 24),
|
||||
child: Text(
|
||||
_isSearching
|
||||
? 'No transactions match this search.'
|
||||
: _selectedDay != null
|
||||
? 'No transactions on this day.'
|
||||
: 'No transactions this month.',
|
||||
textAlign: TextAlign.center,
|
||||
style: theme.textTheme.bodyMedium,
|
||||
),
|
||||
),
|
||||
)
|
||||
else
|
||||
for (var i = 0; i < filtered.length; i++) ...[
|
||||
if (i > 0)
|
||||
Divider(
|
||||
height: 1,
|
||||
color: colors.outlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
_CompactTransactionTile(
|
||||
tx: filtered[i],
|
||||
meta: metaController.metaFor(filtered[i]),
|
||||
labels: metaController
|
||||
.labelsFor(metaController.metaFor(filtered[i])),
|
||||
SliverList(
|
||||
delegate: SliverChildBuilderDelegate(
|
||||
(context, index) {
|
||||
final tx = filtered[index];
|
||||
final meta = metaController.metaFor(tx);
|
||||
return Column(
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
if (index > 0)
|
||||
Divider(
|
||||
height: 1,
|
||||
color: colors.outlineVariant.withValues(alpha: 0.5),
|
||||
),
|
||||
_CompactTransactionTile(
|
||||
tx: tx,
|
||||
meta: meta,
|
||||
labels: metaController.leafLabelsFor(meta),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
childCount: filtered.length,
|
||||
addAutomaticKeepAlives: false,
|
||||
),
|
||||
],
|
||||
),
|
||||
const SliverToBoxAdapter(child: SizedBox(height: 32)),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user