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
|
||||
|
||||
Reference in New Issue
Block a user