new favourites feature
This commit is contained in:
@@ -9,6 +9,7 @@ import 'package:provider/provider.dart';
|
||||
import '../models/bank.dart';
|
||||
import '../models/transaction_meta.dart';
|
||||
import '../providers/bank_provider.dart';
|
||||
import '../providers/preferences_provider.dart';
|
||||
import '../providers/tx_meta_provider.dart';
|
||||
import '../utils/app_theme.dart';
|
||||
import '../utils/connect_bank.dart';
|
||||
@@ -16,6 +17,7 @@ import '../utils/helpers.dart';
|
||||
import '../utils/navigation.dart';
|
||||
import '../utils/tx_calendar.dart';
|
||||
import '../widgets/empty_state.dart';
|
||||
import '../widgets/home_widgets_sheet.dart';
|
||||
import '../widgets/label_filter_dialog.dart';
|
||||
import '../widgets/loading_view.dart';
|
||||
import '../widgets/responsive_body.dart';
|
||||
@@ -30,6 +32,9 @@ class TransactionsScreen extends StatefulWidget {
|
||||
this.initialLabelIds = const {},
|
||||
this.initialSearchInMonthOnly,
|
||||
this.initialYear,
|
||||
this.initialQuery,
|
||||
this.initialFlow,
|
||||
this.initialAmountRange,
|
||||
});
|
||||
|
||||
/// When set, opens on this calendar month instead of the current month.
|
||||
@@ -44,6 +49,12 @@ class TransactionsScreen extends StatefulWidget {
|
||||
/// When set, label/search results are limited to this calendar year.
|
||||
final int? initialYear;
|
||||
|
||||
/// Pre-fill search query (e.g. from a Home filter widget).
|
||||
final String? initialQuery;
|
||||
|
||||
final TxFlowFilter? initialFlow;
|
||||
final TxAmountRange? initialAmountRange;
|
||||
|
||||
@override
|
||||
State<TransactionsScreen> createState() => _TransactionsScreenState();
|
||||
}
|
||||
@@ -81,6 +92,13 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
// Default to current month so the list, navigator, and filter popup agree.
|
||||
_searchInMonthOnly = widget.initialSearchInMonthOnly ?? true;
|
||||
_yearFilter = widget.initialYear;
|
||||
_flowFilter = widget.initialFlow ?? TxFlowFilter.all;
|
||||
_amountRange = widget.initialAmountRange ?? const TxAmountRange();
|
||||
final initialQuery = widget.initialQuery?.trim() ?? '';
|
||||
if (initialQuery.isNotEmpty) {
|
||||
_searchController.text = initialQuery;
|
||||
_activeQuery = initialQuery;
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
@@ -222,6 +240,26 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
);
|
||||
}
|
||||
|
||||
Future<void> _saveAsHomeWidget() async {
|
||||
final created = await composeHomeFilterWidget(
|
||||
context,
|
||||
initialFilter: TransactionFilterSelection(
|
||||
labelIds: Set<String>.of(_labelFilters),
|
||||
flow: _flowFilter,
|
||||
amountRange: _amountRange,
|
||||
query: _activeQuery,
|
||||
monthOnly: _searchInMonthOnly,
|
||||
),
|
||||
skipFilterDialog: true,
|
||||
);
|
||||
if (created == null || !mounted) return;
|
||||
await context.read<PreferencesController>().addHomeFilterWidget(created);
|
||||
if (!mounted) return;
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(content: Text('Added “${created.name}” to Home')),
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final bank = context.watch<BankController>();
|
||||
@@ -229,11 +267,18 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Transactions'),
|
||||
actions: bankAppBarActions(
|
||||
context: context,
|
||||
onRefresh: bank.refresh,
|
||||
refreshing: bank.isLoading,
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: 'Save as Home widget',
|
||||
onPressed: _saveAsHomeWidget,
|
||||
icon: const Icon(Icons.dashboard_customize_outlined),
|
||||
),
|
||||
...bankAppBarActions(
|
||||
context: context,
|
||||
onRefresh: bank.refresh,
|
||||
refreshing: bank.isLoading,
|
||||
),
|
||||
],
|
||||
),
|
||||
body: Column(
|
||||
children: [
|
||||
|
||||
Reference in New Issue
Block a user