fix recurrent spendings
This commit is contained in:
@@ -34,7 +34,6 @@ class LookAheadScreen extends StatefulWidget {
|
||||
class _LookAheadScreenState extends State<LookAheadScreen> {
|
||||
var _period = _PeriodMode.monthly;
|
||||
late DateTime _cursor;
|
||||
var _didBackfill = false;
|
||||
List<RecurringItem>? _cachedItems;
|
||||
int? _itemsCacheKey;
|
||||
|
||||
@@ -135,16 +134,6 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
|
||||
final theme = Theme.of(context);
|
||||
final colors = theme.colorScheme;
|
||||
|
||||
if (!_didBackfill && bank.transactions.isNotEmpty) {
|
||||
_didBackfill = true;
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
if (!mounted) return;
|
||||
context
|
||||
.read<TxMetaController>()
|
||||
.ensureAutoRecurringTemplates(bank.transactions);
|
||||
});
|
||||
}
|
||||
|
||||
final balance = bank.balance;
|
||||
final currency = balance?.currency ??
|
||||
(bank.transactions.isNotEmpty
|
||||
@@ -190,6 +179,17 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
|
||||
}
|
||||
}
|
||||
|
||||
// One occurrence of each template per month (template run-rate).
|
||||
var monthlyIncome = 0.0;
|
||||
var monthlyExpense = 0.0;
|
||||
for (final item in items) {
|
||||
if (item.amount >= 0) {
|
||||
monthlyIncome += item.amount;
|
||||
} else {
|
||||
monthlyExpense += -item.amount;
|
||||
}
|
||||
}
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Look ahead'),
|
||||
@@ -303,7 +303,7 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(
|
||||
'Recurring templates',
|
||||
'Recurring spendings',
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
),
|
||||
@@ -317,8 +317,8 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
items.isEmpty
|
||||
? 'Mark transactions as recurring, or create a template.'
|
||||
: '${items.length} template${items.length == 1 ? '' : 's'} · '
|
||||
? '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(
|
||||
@@ -326,13 +326,37 @@ class _LookAheadScreenState extends State<LookAheadScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: _SummaryCard(
|
||||
icon: Icons.south_west,
|
||||
iconBackground: AppTheme.accent.withValues(alpha: 0.18),
|
||||
iconColor: AppTheme.accent,
|
||||
amount: formatMoney(monthlyIncome, currency),
|
||||
label: 'Monthly income',
|
||||
),
|
||||
),
|
||||
const SizedBox(width: 12),
|
||||
Expanded(
|
||||
child: _SummaryCard(
|
||||
icon: Icons.north_east,
|
||||
iconBackground: AppTheme.expense.withValues(alpha: 0.18),
|
||||
iconColor: AppTheme.expense,
|
||||
amount: formatMoney(monthlyExpense, currency),
|
||||
label: 'Monthly expense',
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
const SizedBox(height: 10),
|
||||
if (items.isEmpty)
|
||||
const EmptyState(
|
||||
icon: Icons.event_repeat_outlined,
|
||||
title: 'No recurring templates',
|
||||
title: 'No recurring spendings',
|
||||
message:
|
||||
'Mark a transaction as recurring, or tap New to base a '
|
||||
'template on a transaction or label average.',
|
||||
'Open a transaction and tap Create recurring spending, '
|
||||
'or use New to pick a transaction or label average.',
|
||||
)
|
||||
else
|
||||
Card(
|
||||
@@ -584,7 +608,7 @@ class _TemplateTile extends StatelessWidget {
|
||||
|
||||
return ListTile(
|
||||
leading: IconButton(
|
||||
tooltip: 'Edit template',
|
||||
tooltip: 'Edit spending',
|
||||
icon: Icon(Icons.tune, color: colors.primary),
|
||||
onPressed: tpl == null
|
||||
? null
|
||||
|
||||
@@ -11,6 +11,7 @@ import '../providers/tx_meta_provider.dart';
|
||||
import '../utils/app_theme.dart';
|
||||
import '../utils/helpers.dart';
|
||||
import '../widgets/label_parent_picker.dart';
|
||||
import '../widgets/recurring_template_sheet.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
import '../widgets/similar_match_dialog.dart';
|
||||
|
||||
@@ -409,17 +410,28 @@ class _TransactionDetailScreenState extends State<TransactionDetailScreen> {
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 8),
|
||||
SwitchListTile(
|
||||
ListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
secondary: const Icon(Icons.autorenew),
|
||||
title: const Text('Recurring'),
|
||||
subtitle: const Text('Salary, mortgage, subscriptions…'),
|
||||
value: meta.recurring,
|
||||
onChanged: _busy
|
||||
leading: Icon(
|
||||
Icons.event_repeat,
|
||||
color: colors.primary,
|
||||
),
|
||||
title: const Text('Create recurring spending'),
|
||||
subtitle: Text(
|
||||
metaController.hasRecurringSpendingForTx(tx.id)
|
||||
? 'Already on Look ahead — tap to add another'
|
||||
: 'Add this transaction to Look ahead',
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: colors.onSurfaceVariant,
|
||||
),
|
||||
),
|
||||
trailing: const Icon(Icons.chevron_right),
|
||||
onTap: _busy
|
||||
? null
|
||||
: (value) {
|
||||
context.read<TxMetaController>().setRecurring(tx, value);
|
||||
},
|
||||
: () => showCreateRecurringTemplateSheet(
|
||||
context,
|
||||
initialTx: tx,
|
||||
),
|
||||
),
|
||||
SwitchListTile(
|
||||
contentPadding: EdgeInsets.zero,
|
||||
|
||||
@@ -61,7 +61,6 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
var _showCalendar = false;
|
||||
var _flowFilter = TxFlowFilter.all;
|
||||
var _amountRange = const TxAmountRange();
|
||||
var _recurringOnly = false;
|
||||
|
||||
/// Query actually used for filtering (Enter, or live once ≥3 chars).
|
||||
String _activeQuery = '';
|
||||
@@ -97,13 +96,11 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
bool get _hasListFilters =>
|
||||
_labelFilters.isNotEmpty ||
|
||||
_flowFilter != TxFlowFilter.all ||
|
||||
_amountRange.isActive ||
|
||||
_recurringOnly;
|
||||
_amountRange.isActive;
|
||||
|
||||
bool _matchesExtraFilters(BankTransaction tx, TxMetaController meta) {
|
||||
if (!txMatchesFlow(tx, _flowFilter)) return false;
|
||||
if (!txMatchesAmountRange(tx, _amountRange)) return false;
|
||||
if (_recurringOnly && !meta.metaFor(tx).recurring) return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -172,7 +169,6 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
amountRange: _amountRange,
|
||||
query: _activeQuery,
|
||||
monthOnly: _searchInMonthOnly,
|
||||
recurringOnly: _recurringOnly,
|
||||
),
|
||||
);
|
||||
if (result == null || !mounted) return;
|
||||
@@ -184,7 +180,6 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
_flowFilter = result.flow;
|
||||
_amountRange = result.amountRange;
|
||||
_searchInMonthOnly = result.monthOnly;
|
||||
_recurringOnly = result.recurringOnly;
|
||||
if (!_searchInMonthOnly) {
|
||||
_showCalendar = false;
|
||||
_selectedDay = null;
|
||||
@@ -682,15 +677,6 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
);
|
||||
},
|
||||
),
|
||||
if (_recurringOnly)
|
||||
InputChip(
|
||||
visualDensity: VisualDensity.compact,
|
||||
avatar: const Icon(Icons.event_repeat, size: 14),
|
||||
label: const Text('Recurring'),
|
||||
onDeleted: () {
|
||||
setState(() => _recurringOnly = false);
|
||||
},
|
||||
),
|
||||
for (final id in _labelFilters)
|
||||
if (id == kUncategorizedFilterId)
|
||||
InputChip(
|
||||
@@ -968,7 +954,6 @@ class _CompactTransactionTile extends StatelessWidget {
|
||||
formatIsoDate(tx.date),
|
||||
if (labels.isNotEmpty)
|
||||
labels.map((l) => l.name).join(', '),
|
||||
if (meta.recurring) 'Recurring',
|
||||
if (meta.internalTransfer) 'Transfer',
|
||||
if (meta.hasNotes) 'Note',
|
||||
if (tx.pending) 'Pending',
|
||||
|
||||
Reference in New Issue
Block a user