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
+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,
];