fixed some issues and added label and, or capability

This commit is contained in:
davmar
2026-09-10 22:45:25 +02:00
parent b4d367f056
commit 6cc0de8945
14 changed files with 217 additions and 39 deletions
+42 -21
View File
@@ -9,7 +9,7 @@ import '../models/transaction_meta.dart';
import '../providers/bank_provider.dart';
import '../providers/preferences_provider.dart';
import '../providers/tx_meta_provider.dart';
import '../screens/transaction_detail_screen.dart';
import '../screens/transactions_screen.dart';
import '../utils/app_theme.dart';
import '../utils/helpers.dart';
import '../utils/look_ahead.dart';
@@ -337,17 +337,6 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
),
],
),
const SizedBox(height: 4),
Text(
items.isEmpty
? 'Create a spending from a transaction, or tap New.'
: '${items.length} spending${items.length == 1 ? '' : 's'} · '
'projected income ${formatMoney(income, currency)} · '
'expenses ${formatMoney(expenses, currency)}.',
style: theme.textTheme.bodySmall?.copyWith(
color: colors.onSurfaceVariant,
),
),
const SizedBox(height: 10),
Row(
children: [
@@ -622,6 +611,46 @@ class _TemplateTile extends StatelessWidget {
return null;
}
void _openTransactions(BuildContext context) {
final labelIds = item.labelIds.toSet();
SimilarMatchCriteria? similar;
TxFlowFilter? flow;
String? query;
if (labelIds.isEmpty) {
final tx = _sourceTx;
if (tx != null) {
// Same matching as Look ahead / apply-to-similar for this source tx.
similar = SimilarMatchCriteria(
pattern: defaultSimilarPattern(tx.description),
flow: tx.amount < 0
? TxFlowFilter.expense
: tx.amount > 0
? TxFlowFilter.income
: TxFlowFilter.all,
);
flow = similar.flow;
} else if (template != null && template!.merchantKey.isNotEmpty) {
query = template!.merchantKey;
} else {
query = item.description;
}
}
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => TransactionsScreen(
initialLabelIds: labelIds,
initialLabelMatch: LabelMatchMode.or,
initialQuery: query,
initialFlow: flow,
initialSimilarMatch: similar,
initialSearchInMonthOnly: false,
),
),
);
}
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
@@ -658,15 +687,7 @@ class _TemplateTile extends StatelessWidget {
color: income ? AppTheme.accent : AppTheme.expense,
),
),
onTap: () {
final tx = _sourceTx;
if (tx == null) return;
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => TransactionDetailScreen(tx: tx),
),
);
},
onTap: () => _openTransactions(context),
);
}
}
+5 -4
View File
@@ -628,11 +628,11 @@ class _OverviewScreenState extends State<OverviewScreen> {
currency,
),
label: switch (_labelFlow) {
TxFlowFilter.income => 'Labeled income · $_periodTitle',
TxFlowFilter.expense => 'Labeled spend · $_periodTitle',
TxFlowFilter.income => 'Income · $_periodTitle',
TxFlowFilter.expense => 'Spend · $_periodTitle',
TxFlowFilter.all => _labelInvertChart
? 'Labeled net (expense view) · $_periodTitle'
: 'Labeled net · $_periodTitle',
? 'Net (expense view) · $_periodTitle'
: 'Net · $_periodTitle',
},
),
],
@@ -753,6 +753,7 @@ class _OverviewScreenState extends State<OverviewScreen> {
builder: (_) => TransactionsScreen(
initialMonth: initial,
initialLabelIds: labelIds,
initialLabelMatch: LabelMatchMode.or,
initialSearchInMonthOnly: !yearly && labelIds.isNotEmpty,
initialYear: yearly ? period.year : null,
),
+43 -4
View File
@@ -30,11 +30,13 @@ class TransactionsScreen extends StatefulWidget {
super.key,
this.initialMonth,
this.initialLabelIds = const {},
this.initialLabelMatch = LabelMatchMode.and,
this.initialSearchInMonthOnly,
this.initialYear,
this.initialQuery,
this.initialFlow,
this.initialAmountRange,
this.initialSimilarMatch,
});
/// When set, opens on this calendar month instead of the current month.
@@ -43,6 +45,9 @@ class TransactionsScreen extends StatefulWidget {
/// Pre-select these label filters (e.g. from overview history).
final Set<String> initialLabelIds;
/// AND vs OR for [initialLabelIds] (and later filter edits).
final LabelMatchMode initialLabelMatch;
/// When set, overrides the default "search in month" checkbox.
final bool? initialSearchInMonthOnly;
@@ -55,6 +60,9 @@ class TransactionsScreen extends StatefulWidget {
final TxFlowFilter? initialFlow;
final TxAmountRange? initialAmountRange;
/// Match txs the same way as “apply to similar” / Look ahead transaction source.
final SimilarMatchCriteria? initialSimilarMatch;
@override
State<TransactionsScreen> createState() => _TransactionsScreenState();
}
@@ -68,6 +76,8 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
DateTime? _selectedDay;
late bool _searchInMonthOnly;
late final Set<String> _labelFilters;
late LabelMatchMode _labelMatch;
SimilarMatchCriteria? _similarMatch;
int? _yearFilter;
var _showCalendar = false;
var _flowFilter = TxFlowFilter.all;
@@ -89,6 +99,8 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
_month = start.isAfter(now) ? now : start;
}
_labelFilters = Set<String>.of(widget.initialLabelIds);
_labelMatch = widget.initialLabelMatch;
_similarMatch = widget.initialSimilarMatch;
// Default to current month so the list, navigator, and filter popup agree.
_searchInMonthOnly = widget.initialSearchInMonthOnly ?? true;
_yearFilter = widget.initialYear;
@@ -98,6 +110,11 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
if (initialQuery.isNotEmpty) {
_searchController.text = initialQuery;
_activeQuery = initialQuery;
} else if (_similarMatch != null &&
_similarMatch!.pattern.trim().isNotEmpty) {
// Show the similar pattern in the search field for context; filtering
// uses [txMatchesSimilarCriteria], not plain text contains.
_searchController.text = _similarMatch!.pattern;
}
}
@@ -109,16 +126,23 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
}
bool get _isSearching =>
_activeQuery.trim().isNotEmpty || _labelFilters.isNotEmpty;
_activeQuery.trim().isNotEmpty ||
_labelFilters.isNotEmpty ||
_similarMatch != null;
bool get _hasListFilters =>
_labelFilters.isNotEmpty ||
_flowFilter != TxFlowFilter.all ||
_amountRange.isActive;
_amountRange.isActive ||
_similarMatch != null;
bool _matchesExtraFilters(BankTransaction tx, TxMetaController meta) {
if (!txMatchesFlow(tx, _flowFilter)) return false;
if (!txMatchesAmountRange(tx, _amountRange)) return false;
final similar = _similarMatch;
if (similar != null && !txMatchesSimilarCriteria(tx, similar)) {
return false;
}
return true;
}
@@ -147,6 +171,11 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
final trimmed = value.trim();
_searchDebounceTimer?.cancel();
// Editing the box leaves “similar match” mode and uses plain text search.
if (_similarMatch != null) {
setState(() => _similarMatch = null);
}
if (trimmed.length >= _minLiveSearchChars) {
// TextField updates via the controller; only rebuild the list after debounce.
_searchDebounceTimer = Timer(_searchDebounce, () {
@@ -165,13 +194,19 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
void _onSearchSubmitted(String value) {
_searchDebounceTimer?.cancel();
setState(() => _activeQuery = value.trim());
setState(() {
_similarMatch = null;
_activeQuery = value.trim();
});
}
void _clearSearch() {
_searchDebounceTimer?.cancel();
_searchController.clear();
setState(() => _activeQuery = '');
setState(() {
_activeQuery = '';
_similarMatch = null;
});
}
Future<void> _pickFilters(List<TxLabel> available) async {
@@ -183,6 +218,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
currentMonth: _month,
initial: TransactionFilterSelection(
labelIds: Set<String>.of(_labelFilters),
labelMatch: _labelMatch,
flow: _flowFilter,
amountRange: _amountRange,
query: _activeQuery,
@@ -195,6 +231,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
_labelFilters
..clear()
..addAll(result.labelIds);
_labelMatch = result.labelMatch;
_flowFilter = result.flow;
_amountRange = result.amountRange;
_searchInMonthOnly = result.monthOnly;
@@ -246,6 +283,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
context,
initialFilter: TransactionFilterSelection(
labelIds: Set<String>.of(_labelFilters),
labelMatch: _labelMatch,
flow: _flowFilter,
amountRange: _amountRange,
query: _activeQuery,
@@ -386,6 +424,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
searchPool,
_activeQuery,
labelIds: _labelFilters,
labelMatch: _labelMatch,
))
if (_matchesExtraFilters(tx, metaController)) tx,
];