custom filters
This commit is contained in:
@@ -0,0 +1,43 @@
|
|||||||
|
/// Visibility flags for built-in Home screen sections.
|
||||||
|
library;
|
||||||
|
|
||||||
|
class HomeBuiltInSections {
|
||||||
|
const HomeBuiltInSections({
|
||||||
|
this.showTransactions = true,
|
||||||
|
this.showCategorized = true,
|
||||||
|
this.showRecent = true,
|
||||||
|
});
|
||||||
|
|
||||||
|
static const defaults = HomeBuiltInSections();
|
||||||
|
|
||||||
|
final bool showTransactions;
|
||||||
|
final bool showCategorized;
|
||||||
|
final bool showRecent;
|
||||||
|
|
||||||
|
HomeBuiltInSections copyWith({
|
||||||
|
bool? showTransactions,
|
||||||
|
bool? showCategorized,
|
||||||
|
bool? showRecent,
|
||||||
|
}) {
|
||||||
|
return HomeBuiltInSections(
|
||||||
|
showTransactions: showTransactions ?? this.showTransactions,
|
||||||
|
showCategorized: showCategorized ?? this.showCategorized,
|
||||||
|
showRecent: showRecent ?? this.showRecent,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
Map<String, dynamic> toJson() => {
|
||||||
|
'showTransactions': showTransactions,
|
||||||
|
'showCategorized': showCategorized,
|
||||||
|
'showRecent': showRecent,
|
||||||
|
};
|
||||||
|
|
||||||
|
factory HomeBuiltInSections.fromJson(Map<String, dynamic>? json) {
|
||||||
|
if (json == null) return defaults;
|
||||||
|
return HomeBuiltInSections(
|
||||||
|
showTransactions: json['showTransactions'] as bool? ?? true,
|
||||||
|
showCategorized: json['showCategorized'] as bool? ?? true,
|
||||||
|
showRecent: json['showRecent'] as bool? ?? true,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ class HomeFilterWidget {
|
|||||||
required this.name,
|
required this.name,
|
||||||
this.display = true,
|
this.display = true,
|
||||||
this.sortOrder = 0,
|
this.sortOrder = 0,
|
||||||
|
this.halfWidth = false,
|
||||||
this.labelIds = const [],
|
this.labelIds = const [],
|
||||||
this.flow = TxFlowFilter.all,
|
this.flow = TxFlowFilter.all,
|
||||||
this.amountRange = const TxAmountRange(),
|
this.amountRange = const TxAmountRange(),
|
||||||
@@ -26,6 +27,9 @@ class HomeFilterWidget {
|
|||||||
final bool display;
|
final bool display;
|
||||||
final int sortOrder;
|
final int sortOrder;
|
||||||
|
|
||||||
|
/// When true, the Home card uses half the row width.
|
||||||
|
final bool halfWidth;
|
||||||
|
|
||||||
final List<String> labelIds;
|
final List<String> labelIds;
|
||||||
final TxFlowFilter flow;
|
final TxFlowFilter flow;
|
||||||
final TxAmountRange amountRange;
|
final TxAmountRange amountRange;
|
||||||
@@ -49,6 +53,7 @@ class HomeFilterWidget {
|
|||||||
String? name,
|
String? name,
|
||||||
bool? display,
|
bool? display,
|
||||||
int? sortOrder,
|
int? sortOrder,
|
||||||
|
bool? halfWidth,
|
||||||
List<String>? labelIds,
|
List<String>? labelIds,
|
||||||
TxFlowFilter? flow,
|
TxFlowFilter? flow,
|
||||||
TxAmountRange? amountRange,
|
TxAmountRange? amountRange,
|
||||||
@@ -63,6 +68,7 @@ class HomeFilterWidget {
|
|||||||
name: name ?? this.name,
|
name: name ?? this.name,
|
||||||
display: display ?? this.display,
|
display: display ?? this.display,
|
||||||
sortOrder: sortOrder ?? this.sortOrder,
|
sortOrder: sortOrder ?? this.sortOrder,
|
||||||
|
halfWidth: halfWidth ?? this.halfWidth,
|
||||||
labelIds: labelIds ?? this.labelIds,
|
labelIds: labelIds ?? this.labelIds,
|
||||||
flow: flow ?? this.flow,
|
flow: flow ?? this.flow,
|
||||||
amountRange: amountRange ?? this.amountRange,
|
amountRange: amountRange ?? this.amountRange,
|
||||||
@@ -103,6 +109,7 @@ class HomeFilterWidget {
|
|||||||
'name': name,
|
'name': name,
|
||||||
'display': display,
|
'display': display,
|
||||||
'sortOrder': sortOrder,
|
'sortOrder': sortOrder,
|
||||||
|
'halfWidth': halfWidth,
|
||||||
'labelIds': labelIds,
|
'labelIds': labelIds,
|
||||||
'flow': flow.name,
|
'flow': flow.name,
|
||||||
'amountRange': {
|
'amountRange': {
|
||||||
@@ -135,6 +142,7 @@ class HomeFilterWidget {
|
|||||||
: 'Filter',
|
: 'Filter',
|
||||||
display: json['display'] as bool? ?? true,
|
display: json['display'] as bool? ?? true,
|
||||||
sortOrder: json['sortOrder'] as int? ?? 0,
|
sortOrder: json['sortOrder'] as int? ?? 0,
|
||||||
|
halfWidth: json['halfWidth'] as bool? ?? false,
|
||||||
labelIds: [
|
labelIds: [
|
||||||
for (final id in (json['labelIds'] as List? ?? const []))
|
for (final id in (json['labelIds'] as List? ?? const []))
|
||||||
if (id is String && id.isNotEmpty) id,
|
if (id is String && id.isNotEmpty) id,
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ library;
|
|||||||
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
|
|
||||||
|
import '../models/home_built_in_sections.dart';
|
||||||
import '../models/home_filter_widget.dart';
|
import '../models/home_filter_widget.dart';
|
||||||
import '../models/overview_favourite.dart';
|
import '../models/overview_favourite.dart';
|
||||||
import '../services/storage_service.dart';
|
import '../services/storage_service.dart';
|
||||||
@@ -12,12 +13,14 @@ class PreferencesController extends ChangeNotifier {
|
|||||||
_lookAheadMaxYears = _storage.lookAheadMaxYears;
|
_lookAheadMaxYears = _storage.lookAheadMaxYears;
|
||||||
_overviewFavourites = _storage.loadOverviewFavourites();
|
_overviewFavourites = _storage.loadOverviewFavourites();
|
||||||
_homeFilterWidgets = _storage.loadHomeFilterWidgets();
|
_homeFilterWidgets = _storage.loadHomeFilterWidgets();
|
||||||
|
_homeBuiltInSections = _storage.loadHomeBuiltInSections();
|
||||||
}
|
}
|
||||||
|
|
||||||
final StorageService _storage;
|
final StorageService _storage;
|
||||||
late int _lookAheadMaxYears;
|
late int _lookAheadMaxYears;
|
||||||
late List<OverviewFavourite> _overviewFavourites;
|
late List<OverviewFavourite> _overviewFavourites;
|
||||||
late List<HomeFilterWidget> _homeFilterWidgets;
|
late List<HomeFilterWidget> _homeFilterWidgets;
|
||||||
|
late HomeBuiltInSections _homeBuiltInSections;
|
||||||
|
|
||||||
/// Fired after favourites are persisted (for cloud push debounce).
|
/// Fired after favourites are persisted (for cloud push debounce).
|
||||||
VoidCallback? onFavouritesPersisted;
|
VoidCallback? onFavouritesPersisted;
|
||||||
@@ -50,6 +53,31 @@ class PreferencesController extends ChangeNotifier {
|
|||||||
bool get hasDisplayedHomeFilterWidgets =>
|
bool get hasDisplayedHomeFilterWidgets =>
|
||||||
_homeFilterWidgets.any((w) => w.display);
|
_homeFilterWidgets.any((w) => w.display);
|
||||||
|
|
||||||
|
HomeBuiltInSections get homeBuiltInSections => _homeBuiltInSections;
|
||||||
|
|
||||||
|
Future<void> setHomeBuiltInSections(HomeBuiltInSections sections) async {
|
||||||
|
if (sections.showTransactions == _homeBuiltInSections.showTransactions &&
|
||||||
|
sections.showCategorized == _homeBuiltInSections.showCategorized &&
|
||||||
|
sections.showRecent == _homeBuiltInSections.showRecent) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
_homeBuiltInSections = sections;
|
||||||
|
notifyListeners();
|
||||||
|
await _storage.saveHomeBuiltInSections(sections);
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> setHomeShowTransactions(bool value) => setHomeBuiltInSections(
|
||||||
|
_homeBuiltInSections.copyWith(showTransactions: value),
|
||||||
|
);
|
||||||
|
|
||||||
|
Future<void> setHomeShowCategorized(bool value) => setHomeBuiltInSections(
|
||||||
|
_homeBuiltInSections.copyWith(showCategorized: value),
|
||||||
|
);
|
||||||
|
|
||||||
|
Future<void> setHomeShowRecent(bool value) => setHomeBuiltInSections(
|
||||||
|
_homeBuiltInSections.copyWith(showRecent: value),
|
||||||
|
);
|
||||||
|
|
||||||
Future<void> setLookAheadMaxYears(int years) async {
|
Future<void> setLookAheadMaxYears(int years) async {
|
||||||
final next = years.clamp(1, 30);
|
final next = years.clamp(1, 30);
|
||||||
if (next == _lookAheadMaxYears) return;
|
if (next == _lookAheadMaxYears) return;
|
||||||
@@ -149,6 +177,19 @@ class PreferencesController extends ChangeNotifier {
|
|||||||
await updateHomeFilterWidget(current.copyWith(display: display));
|
await updateHomeFilterWidget(current.copyWith(display: display));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<void> reorderHomeFilterWidgets(int oldIndex, int newIndex) async {
|
||||||
|
if (oldIndex == newIndex) return;
|
||||||
|
final next = [..._homeFilterWidgets];
|
||||||
|
final item = next.removeAt(oldIndex);
|
||||||
|
final target = newIndex.clamp(0, next.length);
|
||||||
|
next.insert(target, item);
|
||||||
|
_homeFilterWidgets = [
|
||||||
|
for (var i = 0; i < next.length; i++) next[i].copyWith(sortOrder: i),
|
||||||
|
];
|
||||||
|
notifyListeners();
|
||||||
|
await _persistHomeWidgets();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> replaceHomeFilterWidgets(
|
Future<void> replaceHomeFilterWidgets(
|
||||||
List<HomeFilterWidget> widgets, {
|
List<HomeFilterWidget> widgets, {
|
||||||
bool notify = true,
|
bool notify = true,
|
||||||
|
|||||||
@@ -39,9 +39,9 @@ class SyncController extends ChangeNotifier {
|
|||||||
_bank = bank,
|
_bank = bank,
|
||||||
_prefs = prefs {
|
_prefs = prefs {
|
||||||
_wasLoggedIn = auth.isLoggedIn;
|
_wasLoggedIn = auth.isLoggedIn;
|
||||||
_meta.onPersisted = _schedulePush;
|
_meta.onPersisted = _scheduleMetaPush;
|
||||||
_prefs.onFavouritesPersisted = _schedulePush;
|
_prefs.onFavouritesPersisted = _scheduleFavouritesPush;
|
||||||
_prefs.onHomeWidgetsPersisted = _schedulePush;
|
_prefs.onHomeWidgetsPersisted = _scheduleHomeWidgetsPush;
|
||||||
_auth.addListener(_onAuthChanged);
|
_auth.addListener(_onAuthChanged);
|
||||||
_bank.onAfterSuccessfulLoad = _onBankDataLoaded;
|
_bank.onAfterSuccessfulLoad = _onBankDataLoaded;
|
||||||
if (_auth.isLoggedIn) {
|
if (_auth.isLoggedIn) {
|
||||||
@@ -58,6 +58,9 @@ class SyncController extends ChangeNotifier {
|
|||||||
bool _syncing = false;
|
bool _syncing = false;
|
||||||
bool _pushQueued = false;
|
bool _pushQueued = false;
|
||||||
bool _queuedFullSync = false;
|
bool _queuedFullSync = false;
|
||||||
|
bool _pushMetaPending = false;
|
||||||
|
bool _pushFavouritesPending = false;
|
||||||
|
bool _pushHomeWidgetsPending = false;
|
||||||
Timer? _pushDebounce;
|
Timer? _pushDebounce;
|
||||||
Timer? _progressHold;
|
Timer? _progressHold;
|
||||||
Timer? _uiNotifyThrottle;
|
Timer? _uiNotifyThrottle;
|
||||||
@@ -187,6 +190,10 @@ class SyncController extends ChangeNotifier {
|
|||||||
_progressHold?.cancel();
|
_progressHold?.cancel();
|
||||||
_uiNotifyThrottle?.cancel();
|
_uiNotifyThrottle?.cancel();
|
||||||
_uiNotifyQueued = false;
|
_uiNotifyQueued = false;
|
||||||
|
_pushQueued = false;
|
||||||
|
_pushMetaPending = false;
|
||||||
|
_pushFavouritesPending = false;
|
||||||
|
_pushHomeWidgetsPending = false;
|
||||||
_lastError = null;
|
_lastError = null;
|
||||||
_statusDetail = '';
|
_statusDetail = '';
|
||||||
_showProgressRing = false;
|
_showProgressRing = false;
|
||||||
@@ -224,8 +231,27 @@ class SyncController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void _schedulePush() {
|
void _scheduleMetaPush() {
|
||||||
|
_pushMetaPending = true;
|
||||||
|
_armPushDebounce();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scheduleFavouritesPush() {
|
||||||
|
_pushFavouritesPending = true;
|
||||||
|
_armPushDebounce();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _scheduleHomeWidgetsPush() {
|
||||||
|
_pushHomeWidgetsPending = true;
|
||||||
|
_armPushDebounce();
|
||||||
|
}
|
||||||
|
|
||||||
|
void _armPushDebounce() {
|
||||||
if (!_auth.isLoggedIn) return;
|
if (!_auth.isLoggedIn) return;
|
||||||
|
if (_syncing) {
|
||||||
|
_pushQueued = true;
|
||||||
|
return;
|
||||||
|
}
|
||||||
_pushDebounce?.cancel();
|
_pushDebounce?.cancel();
|
||||||
_pushDebounce = Timer(const Duration(seconds: 2), () {
|
_pushDebounce = Timer(const Duration(seconds: 2), () {
|
||||||
unawaited(_pushOnly());
|
unawaited(_pushOnly());
|
||||||
@@ -370,53 +396,100 @@ class SyncController extends ChangeNotifier {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Annotation-only push after local meta edits (avoids re-uploading 4k+ txs).
|
/// Pushes only the stores that changed locally (debounced).
|
||||||
|
///
|
||||||
|
/// Annotation edits push tx_meta; favourite / Home-widget edits do not
|
||||||
|
/// re-upload the full annotation store or bank transactions.
|
||||||
Future<void> _pushOnly() async {
|
Future<void> _pushOnly() async {
|
||||||
if (!_auth.isLoggedIn || _syncing) {
|
if (!_auth.isLoggedIn) return;
|
||||||
if (_syncing) _pushQueued = true;
|
if (_syncing) {
|
||||||
|
_pushQueued = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
final pushMeta = _pushMetaPending;
|
||||||
|
final pushFavourites = _pushFavouritesPending;
|
||||||
|
final pushHomeWidgets = _pushHomeWidgetsPending;
|
||||||
|
_pushMetaPending = false;
|
||||||
|
_pushFavouritesPending = false;
|
||||||
|
_pushHomeWidgetsPending = false;
|
||||||
|
if (!pushMeta && !pushFavourites && !pushHomeWidgets) return;
|
||||||
|
|
||||||
_progressHold?.cancel();
|
_progressHold?.cancel();
|
||||||
_syncing = true;
|
_syncing = true;
|
||||||
_progressSuccess = false;
|
_progressSuccess = false;
|
||||||
_statusDetail = 'Pushing…';
|
|
||||||
|
final label = switch ((pushMeta, pushFavourites, pushHomeWidgets)) {
|
||||||
|
(false, false, true) => 'Home widgets',
|
||||||
|
(false, true, false) => 'Favourites',
|
||||||
|
(false, true, true) => 'Home layout',
|
||||||
|
(true, false, false) => 'Annotations',
|
||||||
|
_ => 'Changes',
|
||||||
|
};
|
||||||
|
_statusDetail = 'Pushing $label…';
|
||||||
_setProgress(0.05);
|
_setProgress(0.05);
|
||||||
_announce('Syncing…', isProgress: true);
|
_announce('Saving $label…', isProgress: true);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final service = PbSyncService(_auth.client);
|
final service = PbSyncService(_auth.client);
|
||||||
|
final parts = <String>[];
|
||||||
|
var done = 0;
|
||||||
|
final total = (pushMeta ? 1 : 0) +
|
||||||
|
(pushFavourites ? 1 : 0) +
|
||||||
|
(pushHomeWidgets ? 1 : 0);
|
||||||
|
void bump() {
|
||||||
|
done++;
|
||||||
|
_setProgress(done / total);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pushMeta) {
|
||||||
|
_setStatus('Pushing annotations…');
|
||||||
final summary = await service.push(
|
final summary = await service.push(
|
||||||
_meta.exportStore(),
|
_meta.exportStore(),
|
||||||
progressStart: 0.05,
|
progressStart: done / total,
|
||||||
progressEnd: 0.9,
|
progressEnd: (done + 1) / total,
|
||||||
onProgress: _setProgress,
|
onProgress: _setProgress,
|
||||||
onStatus: _setStatus,
|
onStatus: _setStatus,
|
||||||
);
|
);
|
||||||
|
parts.add(summary);
|
||||||
|
bump();
|
||||||
|
}
|
||||||
|
if (pushFavourites) {
|
||||||
|
_setStatus('Pushing favourites…');
|
||||||
try {
|
try {
|
||||||
await service.pushOverviewFavourites(
|
await service.pushOverviewFavourites(
|
||||||
_prefs.overviewFavourites,
|
_prefs.overviewFavourites,
|
||||||
onStatus: _setStatus,
|
onStatus: _setStatus,
|
||||||
);
|
);
|
||||||
|
parts.add('Favourites updated');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'SyncController: overview_favourites push skipped ($error)',
|
'SyncController: overview_favourites push skipped ($error)',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
bump();
|
||||||
|
}
|
||||||
|
if (pushHomeWidgets) {
|
||||||
|
_setStatus('Pushing home widgets…');
|
||||||
try {
|
try {
|
||||||
await service.pushHomeFilterWidgets(
|
await service.pushHomeFilterWidgets(
|
||||||
_prefs.homeFilterWidgets,
|
_prefs.homeFilterWidgets,
|
||||||
onStatus: _setStatus,
|
onStatus: _setStatus,
|
||||||
);
|
);
|
||||||
|
parts.add('Home widgets updated');
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
debugPrint(
|
debugPrint(
|
||||||
'SyncController: home_filter_widgets push skipped ($error)',
|
'SyncController: home_filter_widgets push skipped ($error)',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
bump();
|
||||||
|
}
|
||||||
|
|
||||||
_setProgress(1.0);
|
_setProgress(1.0);
|
||||||
_lastSyncedAt = DateTime.now();
|
_lastSyncedAt = DateTime.now();
|
||||||
_lastError = null;
|
_lastError = null;
|
||||||
_lastSyncSummary = summary;
|
_lastSyncSummary = parts.isEmpty ? label : parts.join('\n');
|
||||||
_announce('Sync complete');
|
_announce('Saved $label');
|
||||||
_syncing = false;
|
_syncing = false;
|
||||||
_finishProgress(success: true);
|
_finishProgress(success: true);
|
||||||
} catch (error, stackTrace) {
|
} catch (error, stackTrace) {
|
||||||
|
|||||||
+232
-22
@@ -4,6 +4,7 @@ library;
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
|
import '../models/home_filter_widget.dart';
|
||||||
import '../providers/bank_provider.dart';
|
import '../providers/bank_provider.dart';
|
||||||
import '../providers/preferences_provider.dart';
|
import '../providers/preferences_provider.dart';
|
||||||
import '../providers/tx_meta_provider.dart';
|
import '../providers/tx_meta_provider.dart';
|
||||||
@@ -45,11 +46,11 @@ class _HomeScreenState extends State<HomeScreen> {
|
|||||||
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text(_editingWidgets ? 'Edit widgets' : 'Home'),
|
title: Text(_editingWidgets ? 'Edit Home' : 'Home'),
|
||||||
actions: [
|
actions: [
|
||||||
if (bank.isLinked || bank.hasData)
|
if (bank.isLinked || bank.hasData)
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: _editingWidgets ? 'Done' : 'Edit Home widgets',
|
tooltip: _editingWidgets ? 'Done' : 'Edit Home layout',
|
||||||
onPressed: () =>
|
onPressed: () =>
|
||||||
setState(() => _editingWidgets = !_editingWidgets),
|
setState(() => _editingWidgets = !_editingWidgets),
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
@@ -218,41 +219,74 @@ class _HomeBody extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
if (_showBuiltIn(
|
||||||
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showTransactions,
|
||||||
|
) ||
|
||||||
|
_showBuiltIn(
|
||||||
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showCategorized,
|
||||||
|
)) ...[
|
||||||
const SizedBox(height: 20),
|
const SizedBox(height: 20),
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
|
if (_showBuiltIn(
|
||||||
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showTransactions,
|
||||||
|
))
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: _EditableHomeBlock(
|
||||||
|
editing: editingWidgets,
|
||||||
|
visible: prefs.homeBuiltInSections.showTransactions,
|
||||||
|
onToggleVisible: (value) =>
|
||||||
|
prefs.setHomeShowTransactions(value),
|
||||||
child: _StatChip(
|
child: _StatChip(
|
||||||
label: 'Transactions',
|
label: 'Transactions',
|
||||||
value: '${bank.transactions.length}',
|
value: '${bank.transactions.length}',
|
||||||
icon: Icons.list_alt,
|
icon: Icons.list_alt,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
if (_showBuiltIn(
|
||||||
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showTransactions,
|
||||||
|
) &&
|
||||||
|
_showBuiltIn(
|
||||||
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showCategorized,
|
||||||
|
))
|
||||||
const SizedBox(width: 10),
|
const SizedBox(width: 10),
|
||||||
|
if (_showBuiltIn(
|
||||||
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showCategorized,
|
||||||
|
))
|
||||||
Expanded(
|
Expanded(
|
||||||
|
child: _EditableHomeBlock(
|
||||||
|
editing: editingWidgets,
|
||||||
|
visible: prefs.homeBuiltInSections.showCategorized,
|
||||||
|
onToggleVisible: (value) =>
|
||||||
|
prefs.setHomeShowCategorized(value),
|
||||||
child: _StatChip(
|
child: _StatChip(
|
||||||
label: 'Categorized',
|
label: 'Categorized',
|
||||||
value: '$categorized',
|
value: '$categorized',
|
||||||
icon: Icons.label_outline,
|
icon: Icons.label_outline,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
],
|
||||||
if (editingWidgets || widgets.isNotEmpty) ...[
|
if (editingWidgets || widgets.isNotEmpty) ...[
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
Row(
|
|
||||||
children: [
|
|
||||||
Text('Widgets', style: theme.textTheme.titleMedium),
|
|
||||||
const Spacer(),
|
|
||||||
if (editingWidgets)
|
if (editingWidgets)
|
||||||
TextButton.icon(
|
Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: TextButton.icon(
|
||||||
onPressed: () => showHomeWidgetsSheet(context),
|
onPressed: () => showHomeWidgetsSheet(context),
|
||||||
icon: const Icon(Icons.add, size: 18),
|
icon: const Icon(Icons.add, size: 18),
|
||||||
label: const Text('Add'),
|
label: const Text('Add'),
|
||||||
),
|
),
|
||||||
],
|
|
||||||
),
|
),
|
||||||
const SizedBox(height: 8),
|
|
||||||
if (widgets.isEmpty)
|
if (widgets.isEmpty)
|
||||||
Text(
|
Text(
|
||||||
'No widgets yet. Tap Add to pin a transaction filter.',
|
'No widgets yet. Tap Add to pin a transaction filter.',
|
||||||
@@ -260,20 +294,74 @@ class _HomeBody extends StatelessWidget {
|
|||||||
color: colors.onSurfaceVariant,
|
color: colors.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
else
|
else if (editingWidgets)
|
||||||
for (final widgetConfig in widgets) ...[
|
ReorderableListView.builder(
|
||||||
HomeFilterWidgetCard(
|
shrinkWrap: true,
|
||||||
|
physics: const NeverScrollableScrollPhysics(),
|
||||||
|
buildDefaultDragHandles: false,
|
||||||
|
itemCount: widgets.length,
|
||||||
|
onReorderItem: prefs.reorderHomeFilterWidgets,
|
||||||
|
proxyDecorator: (child, index, animation) {
|
||||||
|
return Material(
|
||||||
|
elevation: 2,
|
||||||
|
color: Colors.transparent,
|
||||||
|
borderRadius: BorderRadius.circular(16),
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
},
|
||||||
|
itemBuilder: (context, index) {
|
||||||
|
final widgetConfig = widgets[index];
|
||||||
|
return Padding(
|
||||||
|
key: ValueKey(widgetConfig.id),
|
||||||
|
padding: const EdgeInsets.only(bottom: 10),
|
||||||
|
child: _HomeWidgetSlot(
|
||||||
|
halfWidth: widgetConfig.halfWidth,
|
||||||
|
child: HomeFilterWidgetCard(
|
||||||
widgetConfig: widgetConfig,
|
widgetConfig: widgetConfig,
|
||||||
editing: editingWidgets,
|
editing: true,
|
||||||
onRemove: editingWidgets
|
onToggleDisplay: (display) =>
|
||||||
? () => prefs.removeHomeFilterWidget(widgetConfig.id)
|
prefs.setHomeFilterWidgetDisplay(
|
||||||
: null,
|
widgetConfig.id,
|
||||||
|
display,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 10),
|
onEdit: () async {
|
||||||
|
final preferences =
|
||||||
|
context.read<PreferencesController>();
|
||||||
|
final updated = await composeHomeFilterWidget(
|
||||||
|
context,
|
||||||
|
existing: widgetConfig,
|
||||||
|
);
|
||||||
|
if (updated == null) return;
|
||||||
|
await preferences.updateHomeFilterWidget(updated);
|
||||||
|
},
|
||||||
|
dragHandle: ReorderableDragStartListener(
|
||||||
|
index: index,
|
||||||
|
child: Icon(
|
||||||
|
Icons.drag_handle,
|
||||||
|
color: colors.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
)
|
||||||
|
else
|
||||||
|
..._packedHomeWidgetRows(widgets),
|
||||||
],
|
],
|
||||||
],
|
if (_showBuiltIn(
|
||||||
if (recent.isNotEmpty) ...[
|
editing: editingWidgets,
|
||||||
|
enabled: prefs.homeBuiltInSections.showRecent,
|
||||||
|
) &&
|
||||||
|
(recent.isNotEmpty || editingWidgets)) ...[
|
||||||
const SizedBox(height: 24),
|
const SizedBox(height: 24),
|
||||||
|
_EditableHomeBlock(
|
||||||
|
editing: editingWidgets,
|
||||||
|
visible: prefs.homeBuiltInSections.showRecent,
|
||||||
|
onToggleVisible: (value) => prefs.setHomeShowRecent(value),
|
||||||
|
child: Column(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
|
children: [
|
||||||
Row(
|
Row(
|
||||||
children: [
|
children: [
|
||||||
Text('Recent', style: theme.textTheme.titleMedium),
|
Text('Recent', style: theme.textTheme.titleMedium),
|
||||||
@@ -285,6 +373,14 @@ class _HomeBody extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
|
if (recent.isEmpty)
|
||||||
|
Text(
|
||||||
|
'No recent transactions yet.',
|
||||||
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
|
color: colors.onSurfaceVariant,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
else
|
||||||
for (final tx in recent)
|
for (final tx in recent)
|
||||||
ListTile(
|
ListTile(
|
||||||
contentPadding: EdgeInsets.zero,
|
contentPadding: EdgeInsets.zero,
|
||||||
@@ -293,7 +389,8 @@ class _HomeBody extends StatelessWidget {
|
|||||||
builder: (context) {
|
builder: (context) {
|
||||||
final labels =
|
final labels =
|
||||||
meta.leafLabelsFor(meta.metaFor(tx));
|
meta.leafLabelsFor(meta.metaFor(tx));
|
||||||
final label = labels.isEmpty ? null : labels.first;
|
final label =
|
||||||
|
labels.isEmpty ? null : labels.first;
|
||||||
return Icon(
|
return Icon(
|
||||||
label?.icon ?? Icons.receipt_long_outlined,
|
label?.icon ?? Icons.receipt_long_outlined,
|
||||||
color: label?.color,
|
color: label?.color,
|
||||||
@@ -314,15 +411,21 @@ class _HomeBody extends StatelessWidget {
|
|||||||
: AppTheme.expense,
|
: AppTheme.expense,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: editingWidgets
|
||||||
|
? null
|
||||||
|
: () {
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute<void>(
|
MaterialPageRoute<void>(
|
||||||
builder: (_) => TransactionDetailScreen(tx: tx),
|
builder: (_) =>
|
||||||
|
TransactionDetailScreen(tx: tx),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
if (bank.error != null) ...[
|
if (bank.error != null) ...[
|
||||||
const SizedBox(height: 12),
|
const SizedBox(height: 12),
|
||||||
Text(
|
Text(
|
||||||
@@ -382,3 +485,110 @@ class _StatChip extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool _showBuiltIn({required bool editing, required bool enabled}) =>
|
||||||
|
editing || enabled;
|
||||||
|
|
||||||
|
/// Wraps a built-in Home block with show/hide controls while editing.
|
||||||
|
class _EditableHomeBlock extends StatelessWidget {
|
||||||
|
const _EditableHomeBlock({
|
||||||
|
required this.editing,
|
||||||
|
required this.visible,
|
||||||
|
required this.onToggleVisible,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool editing;
|
||||||
|
final bool visible;
|
||||||
|
final ValueChanged<bool> onToggleVisible;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
final colors = Theme.of(context).colorScheme;
|
||||||
|
final content = Opacity(
|
||||||
|
opacity: editing && !visible ? 0.45 : 1,
|
||||||
|
child: child,
|
||||||
|
);
|
||||||
|
if (!editing) return content;
|
||||||
|
return Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(child: content),
|
||||||
|
IconButton(
|
||||||
|
tooltip: visible ? 'Hide from Home' : 'Show on Home',
|
||||||
|
onPressed: () => onToggleVisible(!visible),
|
||||||
|
icon: Icon(
|
||||||
|
visible ? Icons.visibility_outlined : Icons.visibility_off_outlined,
|
||||||
|
color: visible ? colors.onSurfaceVariant : colors.primary,
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Full- or half-width slot for a Home filter widget card.
|
||||||
|
class _HomeWidgetSlot extends StatelessWidget {
|
||||||
|
const _HomeWidgetSlot({
|
||||||
|
required this.halfWidth,
|
||||||
|
required this.child,
|
||||||
|
});
|
||||||
|
|
||||||
|
final bool halfWidth;
|
||||||
|
final Widget child;
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) {
|
||||||
|
if (!halfWidth) return child;
|
||||||
|
return LayoutBuilder(
|
||||||
|
builder: (context, constraints) {
|
||||||
|
final width = (constraints.maxWidth - 10) / 2;
|
||||||
|
return Align(
|
||||||
|
alignment: Alignment.centerLeft,
|
||||||
|
child: SizedBox(width: width, child: child),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
List<Widget> _packedHomeWidgetRows(List<HomeFilterWidget> widgets) {
|
||||||
|
final rows = <Widget>[];
|
||||||
|
var i = 0;
|
||||||
|
while (i < widgets.length) {
|
||||||
|
final a = widgets[i];
|
||||||
|
final canPair = a.halfWidth &&
|
||||||
|
i + 1 < widgets.length &&
|
||||||
|
widgets[i + 1].halfWidth;
|
||||||
|
if (canPair) {
|
||||||
|
final b = widgets[i + 1];
|
||||||
|
rows.add(
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 10),
|
||||||
|
child: Row(
|
||||||
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
|
children: [
|
||||||
|
Expanded(child: HomeFilterWidgetCard(widgetConfig: a)),
|
||||||
|
const SizedBox(width: 10),
|
||||||
|
Expanded(child: HomeFilterWidgetCard(widgetConfig: b)),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
i += 2;
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
rows.add(
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.only(bottom: 10),
|
||||||
|
child: _HomeWidgetSlot(
|
||||||
|
halfWidth: a.halfWidth,
|
||||||
|
child: HomeFilterWidgetCard(widgetConfig: a),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
);
|
||||||
|
i += 1;
|
||||||
|
}
|
||||||
|
return rows;
|
||||||
|
}
|
||||||
|
|||||||
@@ -241,6 +241,7 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _saveAsHomeWidget() async {
|
Future<void> _saveAsHomeWidget() async {
|
||||||
|
final preferences = context.read<PreferencesController>();
|
||||||
final created = await composeHomeFilterWidget(
|
final created = await composeHomeFilterWidget(
|
||||||
context,
|
context,
|
||||||
initialFilter: TransactionFilterSelection(
|
initialFilter: TransactionFilterSelection(
|
||||||
@@ -252,8 +253,8 @@ class _TransactionsScreenState extends State<TransactionsScreen> {
|
|||||||
),
|
),
|
||||||
skipFilterDialog: true,
|
skipFilterDialog: true,
|
||||||
);
|
);
|
||||||
if (created == null || !mounted) return;
|
if (created == null) return;
|
||||||
await context.read<PreferencesController>().addHomeFilterWidget(created);
|
await preferences.addHomeFilterWidget(created);
|
||||||
if (!mounted) return;
|
if (!mounted) return;
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
SnackBar(content: Text('Added “${created.name}” to Home')),
|
SnackBar(content: Text('Added “${created.name}” to Home')),
|
||||||
|
|||||||
@@ -520,6 +520,7 @@ class PbSyncService {
|
|||||||
'name': r.getStringValue('name'),
|
'name': r.getStringValue('name'),
|
||||||
'display': r.getBoolValue('display', true),
|
'display': r.getBoolValue('display', true),
|
||||||
'sortOrder': r.getIntValue('sort_order', 0),
|
'sortOrder': r.getIntValue('sort_order', 0),
|
||||||
|
'halfWidth': r.getBoolValue('half_width'),
|
||||||
'labelIds': _jsonStringList(r.get<dynamic>('label_ids')),
|
'labelIds': _jsonStringList(r.get<dynamic>('label_ids')),
|
||||||
'flow': r.getStringValue('flow'),
|
'flow': r.getStringValue('flow'),
|
||||||
'amountRange': rangeRaw is Map
|
'amountRange': rangeRaw is Map
|
||||||
@@ -1197,6 +1198,7 @@ class PbSyncService {
|
|||||||
'name': _clip(w.name.isEmpty ? 'Filter' : w.name, 200),
|
'name': _clip(w.name.isEmpty ? 'Filter' : w.name, 200),
|
||||||
'display': w.display,
|
'display': w.display,
|
||||||
'sort_order': w.sortOrder,
|
'sort_order': w.sortOrder,
|
||||||
|
'half_width': w.halfWidth,
|
||||||
'label_ids': w.labelIds,
|
'label_ids': w.labelIds,
|
||||||
'flow': w.flow.name,
|
'flow': w.flow.name,
|
||||||
'amount_range': {
|
'amount_range': {
|
||||||
@@ -1297,6 +1299,7 @@ class PbSyncService {
|
|||||||
return remote.getStringValue('name') == w.name &&
|
return remote.getStringValue('name') == w.name &&
|
||||||
remote.getBoolValue('display', true) == w.display &&
|
remote.getBoolValue('display', true) == w.display &&
|
||||||
remote.getIntValue('sort_order', 0) == w.sortOrder &&
|
remote.getIntValue('sort_order', 0) == w.sortOrder &&
|
||||||
|
remote.getBoolValue('half_width') == w.halfWidth &&
|
||||||
_sameIdList(remoteIds, w.labelIds) &&
|
_sameIdList(remoteIds, w.labelIds) &&
|
||||||
remote.getStringValue('flow') == w.flow.name &&
|
remote.getStringValue('flow') == w.flow.name &&
|
||||||
asDouble(rangeMap['exact']) == w.amountRange.exact &&
|
asDouble(rangeMap['exact']) == w.amountRange.exact &&
|
||||||
|
|||||||
@@ -7,6 +7,7 @@ import 'package:flutter/foundation.dart';
|
|||||||
import 'package:shared_preferences/shared_preferences.dart';
|
import 'package:shared_preferences/shared_preferences.dart';
|
||||||
|
|
||||||
import '../models/bank.dart';
|
import '../models/bank.dart';
|
||||||
|
import '../models/home_built_in_sections.dart';
|
||||||
import '../models/home_filter_widget.dart';
|
import '../models/home_filter_widget.dart';
|
||||||
import '../models/overview_favourite.dart';
|
import '../models/overview_favourite.dart';
|
||||||
import '../models/transaction_meta.dart';
|
import '../models/transaction_meta.dart';
|
||||||
@@ -183,6 +184,27 @@ class StorageService {
|
|||||||
return _prefs.setString(StorageKeys.homeFilterWidgets, encoded);
|
return _prefs.setString(StorageKeys.homeFilterWidgets, encoded);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
HomeBuiltInSections loadHomeBuiltInSections() {
|
||||||
|
final raw = _prefs.getString(StorageKeys.homeBuiltInSections);
|
||||||
|
if (raw == null || raw.isEmpty) return HomeBuiltInSections.defaults;
|
||||||
|
try {
|
||||||
|
final decoded = jsonDecode(raw);
|
||||||
|
if (decoded is! Map) return HomeBuiltInSections.defaults;
|
||||||
|
return HomeBuiltInSections.fromJson(
|
||||||
|
Map<String, dynamic>.from(decoded),
|
||||||
|
);
|
||||||
|
} catch (_) {
|
||||||
|
return HomeBuiltInSections.defaults;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<void> saveHomeBuiltInSections(HomeBuiltInSections sections) {
|
||||||
|
return _prefs.setString(
|
||||||
|
StorageKeys.homeBuiltInSections,
|
||||||
|
jsonEncode(sections.toJson()),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
bool get useRemoteData => _prefs.getBool(StorageKeys.useRemoteData) ?? false;
|
bool get useRemoteData => _prefs.getBool(StorageKeys.useRemoteData) ?? false;
|
||||||
|
|
||||||
Future<void> setUseRemoteData(bool value) {
|
Future<void> setUseRemoteData(bool value) {
|
||||||
|
|||||||
@@ -57,6 +57,9 @@ abstract final class StorageKeys {
|
|||||||
|
|
||||||
/// Home screen filter widgets (JSON list).
|
/// Home screen filter widgets (JSON list).
|
||||||
static const homeFilterWidgets = 'home_filter_widgets_v1';
|
static const homeFilterWidgets = 'home_filter_widgets_v1';
|
||||||
|
|
||||||
|
/// Built-in Home sections visibility (Transactions / Categorized / Recent).
|
||||||
|
static const homeBuiltInSections = 'home_built_in_sections_v1';
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Named routes registered on [MaterialApp].
|
/// Named routes registered on [MaterialApp].
|
||||||
|
|||||||
@@ -17,14 +17,18 @@ class HomeFilterWidgetCard extends StatelessWidget {
|
|||||||
super.key,
|
super.key,
|
||||||
required this.widgetConfig,
|
required this.widgetConfig,
|
||||||
this.editing = false,
|
this.editing = false,
|
||||||
this.onRemove,
|
this.onToggleDisplay,
|
||||||
|
this.onEdit,
|
||||||
|
this.dragHandle,
|
||||||
});
|
});
|
||||||
|
|
||||||
final HomeFilterWidget widgetConfig;
|
final HomeFilterWidget widgetConfig;
|
||||||
final bool editing;
|
final bool editing;
|
||||||
final VoidCallback? onRemove;
|
final ValueChanged<bool>? onToggleDisplay;
|
||||||
|
final VoidCallback? onEdit;
|
||||||
|
final Widget? dragHandle;
|
||||||
|
|
||||||
void _open(BuildContext context) {
|
void _openTransactions(BuildContext context) {
|
||||||
final filter = widgetConfig.filter;
|
final filter = widgetConfig.filter;
|
||||||
Navigator.of(context).push(
|
Navigator.of(context).push(
|
||||||
MaterialPageRoute<void>(
|
MaterialPageRoute<void>(
|
||||||
@@ -56,17 +60,32 @@ class HomeFilterWidgetCard extends StatelessWidget {
|
|||||||
filter: widgetConfig.filter,
|
filter: widgetConfig.filter,
|
||||||
);
|
);
|
||||||
|
|
||||||
return Card(
|
final hidden = editing && !widgetConfig.display;
|
||||||
|
|
||||||
|
return Opacity(
|
||||||
|
opacity: hidden ? 0.45 : 1,
|
||||||
|
child: Card(
|
||||||
color: colors.surfaceContainer,
|
color: colors.surfaceContainer,
|
||||||
elevation: 0,
|
elevation: 0,
|
||||||
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(16)),
|
||||||
child: InkWell(
|
child: InkWell(
|
||||||
borderRadius: BorderRadius.circular(16),
|
borderRadius: BorderRadius.circular(16),
|
||||||
onTap: editing ? null : () => _open(context),
|
onTap: editing
|
||||||
|
? onEdit
|
||||||
|
: () => _openTransactions(context),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(14, 12, 8, 12),
|
padding: EdgeInsets.fromLTRB(
|
||||||
|
14,
|
||||||
|
12,
|
||||||
|
editing ? 4 : 14,
|
||||||
|
12,
|
||||||
|
),
|
||||||
child: Row(
|
child: Row(
|
||||||
children: [
|
children: [
|
||||||
|
if (dragHandle != null) ...[
|
||||||
|
dragHandle!,
|
||||||
|
const SizedBox(width: 4),
|
||||||
|
],
|
||||||
Expanded(
|
Expanded(
|
||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
@@ -107,24 +126,27 @@ class HomeFilterWidgetCard extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
if (editing)
|
if (editing && onToggleDisplay != null)
|
||||||
IconButton(
|
IconButton(
|
||||||
tooltip: 'Remove from Home',
|
tooltip: widgetConfig.display
|
||||||
onPressed: onRemove,
|
? 'Hide from Home'
|
||||||
|
: 'Show on Home',
|
||||||
|
onPressed: () =>
|
||||||
|
onToggleDisplay!(!widgetConfig.display),
|
||||||
icon: Icon(
|
icon: Icon(
|
||||||
Icons.remove_circle_outline,
|
widgetConfig.display
|
||||||
color: colors.error,
|
? Icons.remove_circle_outline
|
||||||
|
: Icons.add_circle_outline,
|
||||||
|
color: widgetConfig.display
|
||||||
|
? colors.error
|
||||||
|
: colors.primary,
|
||||||
),
|
),
|
||||||
)
|
|
||||||
else
|
|
||||||
Icon(
|
|
||||||
Icons.chevron_right,
|
|
||||||
color: colors.onSurfaceVariant,
|
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,28 +34,33 @@ Future<HomeFilterWidget?> composeHomeFilterWidget(
|
|||||||
HomeFilterWidget? existing,
|
HomeFilterWidget? existing,
|
||||||
bool skipFilterDialog = false,
|
bool skipFilterDialog = false,
|
||||||
}) async {
|
}) async {
|
||||||
TransactionFilterSelection? filter = initialFilter ?? existing?.filter;
|
// Capture before any modal opens — the caller's element may be rebuilt.
|
||||||
if (!skipFilterDialog || filter == null) {
|
|
||||||
final bank = context.read<BankController>();
|
final bank = context.read<BankController>();
|
||||||
final meta = context.read<TxMetaController>();
|
final meta = context.read<TxMetaController>();
|
||||||
|
final navigator = Navigator.of(context);
|
||||||
|
|
||||||
|
TransactionFilterSelection? filter = initialFilter ?? existing?.filter;
|
||||||
|
if (!skipFilterDialog || filter == null) {
|
||||||
filter = await showTransactionFilterDialog(
|
filter = await showTransactionFilterDialog(
|
||||||
context,
|
navigator.context,
|
||||||
available: meta.allLabels,
|
available: meta.allLabels,
|
||||||
transactions: bank.transactions,
|
transactions: bank.transactions,
|
||||||
initial: filter ?? const TransactionFilterSelection(labelIds: {}),
|
initial: filter ?? const TransactionFilterSelection(labelIds: {}),
|
||||||
);
|
);
|
||||||
if (filter == null || !context.mounted) return null;
|
if (filter == null || !navigator.mounted) return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!navigator.mounted) return null;
|
||||||
final name = await promptFavouriteName(
|
final name = await promptFavouriteName(
|
||||||
context,
|
navigator.context,
|
||||||
initial: existing?.name ?? '',
|
initial: existing?.name ?? '',
|
||||||
title: existing == null ? 'Name this widget' : 'Rename widget',
|
title: existing == null ? 'Name this widget' : 'Rename widget',
|
||||||
);
|
);
|
||||||
if (name == null || !context.mounted) return null;
|
if (name == null || !navigator.mounted) return null;
|
||||||
|
|
||||||
await Future<void>.delayed(Duration.zero);
|
// Let the name dialog finish popping before presenting options.
|
||||||
if (!context.mounted) return null;
|
await WidgetsBinding.instance.endOfFrame;
|
||||||
|
if (!navigator.mounted) return null;
|
||||||
|
|
||||||
final draft = existing == null
|
final draft = existing == null
|
||||||
? HomeFilterWidget.fromFilter(name: name, filter: filter)
|
? HomeFilterWidget.fromFilter(name: name, filter: filter)
|
||||||
@@ -68,7 +73,7 @@ Future<HomeFilterWidget?> composeHomeFilterWidget(
|
|||||||
monthOnly: filter.monthOnly,
|
monthOnly: filter.monthOnly,
|
||||||
);
|
);
|
||||||
|
|
||||||
return _promptWidgetMetrics(context, draft);
|
return _promptWidgetMetrics(navigator.context, draft);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<HomeFilterWidget?> _promptWidgetMetrics(
|
Future<HomeFilterWidget?> _promptWidgetMetrics(
|
||||||
@@ -78,6 +83,7 @@ Future<HomeFilterWidget?> _promptWidgetMetrics(
|
|||||||
var showIn = draft.showAmountIn;
|
var showIn = draft.showAmountIn;
|
||||||
var showOut = draft.showAmountOut;
|
var showOut = draft.showAmountOut;
|
||||||
var showCount = draft.showCount;
|
var showCount = draft.showCount;
|
||||||
|
var halfWidth = draft.halfWidth;
|
||||||
|
|
||||||
return showDialog<HomeFilterWidget>(
|
return showDialog<HomeFilterWidget>(
|
||||||
context: context,
|
context: context,
|
||||||
@@ -86,7 +92,7 @@ Future<HomeFilterWidget?> _promptWidgetMetrics(
|
|||||||
return StatefulBuilder(
|
return StatefulBuilder(
|
||||||
builder: (context, setState) {
|
builder: (context, setState) {
|
||||||
return AlertDialog(
|
return AlertDialog(
|
||||||
title: const Text('Widget metrics'),
|
title: const Text('Widget options'),
|
||||||
content: Column(
|
content: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: [
|
children: [
|
||||||
@@ -111,6 +117,13 @@ Future<HomeFilterWidget?> _promptWidgetMetrics(
|
|||||||
onChanged: (value) =>
|
onChanged: (value) =>
|
||||||
setState(() => showCount = value ?? false),
|
setState(() => showCount = value ?? false),
|
||||||
),
|
),
|
||||||
|
SwitchListTile(
|
||||||
|
contentPadding: EdgeInsets.zero,
|
||||||
|
title: const Text('Half width'),
|
||||||
|
subtitle: const Text('Share the row with another widget'),
|
||||||
|
value: halfWidth,
|
||||||
|
onChanged: (value) => setState(() => halfWidth = value),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
actions: [
|
actions: [
|
||||||
@@ -126,6 +139,7 @@ Future<HomeFilterWidget?> _promptWidgetMetrics(
|
|||||||
showAmountIn: showIn,
|
showAmountIn: showIn,
|
||||||
showAmountOut: showOut,
|
showAmountOut: showOut,
|
||||||
showCount: showCount,
|
showCount: showCount,
|
||||||
|
halfWidth: halfWidth,
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
@@ -161,11 +175,11 @@ class _HomeWidgetsSheet extends StatelessWidget {
|
|||||||
child: Column(
|
child: Column(
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text('Home widgets', style: theme.textTheme.titleLarge),
|
Text('Home layout', style: theme.textTheme.titleLarge),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
'Pin saved transaction filters on Home. Check Display to '
|
'Choose which built-in sections and filter widgets appear '
|
||||||
'show a widget; edit metrics or remove anytime.',
|
'on Home. Check Display to show an item.',
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
),
|
),
|
||||||
@@ -174,12 +188,51 @@ class _HomeWidgetsSheet extends StatelessWidget {
|
|||||||
),
|
),
|
||||||
),
|
),
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.fromLTRB(16, 0, 16, 8),
|
padding: const EdgeInsets.fromLTRB(8, 0, 8, 0),
|
||||||
|
child: Column(
|
||||||
|
children: [
|
||||||
|
CheckboxListTile(
|
||||||
|
value: prefs.homeBuiltInSections.showTransactions,
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value == null) return;
|
||||||
|
prefs.setHomeShowTransactions(value);
|
||||||
|
},
|
||||||
|
title: const Text('Transactions'),
|
||||||
|
subtitle: const Text('Total transaction count'),
|
||||||
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
|
),
|
||||||
|
CheckboxListTile(
|
||||||
|
value: prefs.homeBuiltInSections.showCategorized,
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value == null) return;
|
||||||
|
prefs.setHomeShowCategorized(value);
|
||||||
|
},
|
||||||
|
title: const Text('Categorized'),
|
||||||
|
subtitle: const Text('Labeled transaction count'),
|
||||||
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
|
),
|
||||||
|
CheckboxListTile(
|
||||||
|
value: prefs.homeBuiltInSections.showRecent,
|
||||||
|
onChanged: (value) {
|
||||||
|
if (value == null) return;
|
||||||
|
prefs.setHomeShowRecent(value);
|
||||||
|
},
|
||||||
|
title: const Text('Recent transactions'),
|
||||||
|
subtitle: const Text('Latest activity list'),
|
||||||
|
controlAffinity: ListTileControlAffinity.leading,
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const Divider(height: 1),
|
||||||
|
Padding(
|
||||||
|
padding: const EdgeInsets.fromLTRB(16, 8, 16, 8),
|
||||||
child: OutlinedButton.icon(
|
child: OutlinedButton.icon(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
|
final preferences = context.read<PreferencesController>();
|
||||||
final created = await composeHomeFilterWidget(context);
|
final created = await composeHomeFilterWidget(context);
|
||||||
if (created == null || !context.mounted) return;
|
if (created == null) return;
|
||||||
await prefs.addHomeFilterWidget(created);
|
await preferences.addHomeFilterWidget(created);
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.add),
|
icon: const Icon(Icons.add),
|
||||||
label: const Text('Add filter widget'),
|
label: const Text('Add filter widget'),
|
||||||
@@ -192,8 +245,8 @@ class _HomeWidgetsSheet extends StatelessWidget {
|
|||||||
child: Padding(
|
child: Padding(
|
||||||
padding: const EdgeInsets.all(24),
|
padding: const EdgeInsets.all(24),
|
||||||
child: Text(
|
child: Text(
|
||||||
'No widgets yet. Add a filter, or save one from '
|
'No filter widgets yet. Add one here, or save a '
|
||||||
'Transactions.',
|
'filter from Transactions.',
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
style: theme.textTheme.bodyMedium?.copyWith(
|
style: theme.textTheme.bodyMedium?.copyWith(
|
||||||
color: theme.colorScheme.onSurfaceVariant,
|
color: theme.colorScheme.onSurfaceVariant,
|
||||||
@@ -216,17 +269,35 @@ class _HomeWidgetsSheet extends StatelessWidget {
|
|||||||
value,
|
value,
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
secondary: IconButton(
|
secondary: PopupMenuButton<String>(
|
||||||
tooltip: 'Edit',
|
tooltip: 'Widget actions',
|
||||||
onPressed: () async {
|
onSelected: (value) async {
|
||||||
final updated = await composeHomeFilterWidget(
|
if (value == 'edit') {
|
||||||
|
final preferences =
|
||||||
|
context.read<PreferencesController>();
|
||||||
|
final updated =
|
||||||
|
await composeHomeFilterWidget(
|
||||||
context,
|
context,
|
||||||
existing: widgetItem,
|
existing: widgetItem,
|
||||||
);
|
);
|
||||||
if (updated == null || !context.mounted) return;
|
if (updated == null) return;
|
||||||
await prefs.updateHomeFilterWidget(updated);
|
await preferences
|
||||||
|
.updateHomeFilterWidget(updated);
|
||||||
|
} else if (value == 'delete') {
|
||||||
|
await prefs
|
||||||
|
.removeHomeFilterWidget(widgetItem.id);
|
||||||
|
}
|
||||||
},
|
},
|
||||||
icon: const Icon(Icons.edit_outlined),
|
itemBuilder: (context) => const [
|
||||||
|
PopupMenuItem(
|
||||||
|
value: 'edit',
|
||||||
|
child: Text('Edit'),
|
||||||
|
),
|
||||||
|
PopupMenuItem(
|
||||||
|
value: 'delete',
|
||||||
|
child: Text('Delete'),
|
||||||
|
),
|
||||||
|
],
|
||||||
),
|
),
|
||||||
title: Text(widgetItem.name),
|
title: Text(widgetItem.name),
|
||||||
subtitle: Text(
|
subtitle: Text(
|
||||||
@@ -254,6 +325,7 @@ class _HomeWidgetsSheet extends StatelessWidget {
|
|||||||
if (w.showAmountIn) 'In',
|
if (w.showAmountIn) 'In',
|
||||||
if (w.showAmountOut) 'Out',
|
if (w.showAmountOut) 'Out',
|
||||||
if (w.showCount) 'Count',
|
if (w.showCount) 'Count',
|
||||||
|
if (w.halfWidth) 'Half',
|
||||||
];
|
];
|
||||||
return parts.isEmpty ? 'All transactions' : parts.join(' · ');
|
return parts.isEmpty ? 'All transactions' : parts.join(' · ');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,8 +9,9 @@ final RouteObserver<ModalRoute<void>> appRouteObserver =
|
|||||||
|
|
||||||
/// Builds via [builder] only when this route is not covered by a pushed page.
|
/// Builds via [builder] only when this route is not covered by a pushed page.
|
||||||
///
|
///
|
||||||
/// Uses [ModalRoute.isCurrent] so nested dialogs above a bottom sheet do not
|
/// Only [PageRoute]s count as covering (via [RouteAware]). Modal bottom sheets
|
||||||
/// falsely "uncover" the page when the dialog pops (sheet still open).
|
/// and dialogs must not tear down the subtree — async flows started from Home
|
||||||
|
/// (e.g. compose widget → name → options) need a mounted context between steps.
|
||||||
class SkipBuildWhenCovered extends StatefulWidget {
|
class SkipBuildWhenCovered extends StatefulWidget {
|
||||||
const SkipBuildWhenCovered({
|
const SkipBuildWhenCovered({
|
||||||
super.key,
|
super.key,
|
||||||
@@ -29,13 +30,6 @@ class _SkipBuildWhenCoveredState extends State<SkipBuildWhenCovered>
|
|||||||
with RouteAware {
|
with RouteAware {
|
||||||
var _covered = false;
|
var _covered = false;
|
||||||
|
|
||||||
void _syncCovered() {
|
|
||||||
final route = ModalRoute.of(context);
|
|
||||||
final covered = route != null && !route.isCurrent;
|
|
||||||
if (covered == _covered) return;
|
|
||||||
setState(() => _covered = covered);
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didChangeDependencies() {
|
void didChangeDependencies() {
|
||||||
super.didChangeDependencies();
|
super.didChangeDependencies();
|
||||||
@@ -43,7 +37,6 @@ class _SkipBuildWhenCoveredState extends State<SkipBuildWhenCovered>
|
|||||||
if (route is PageRoute) {
|
if (route is PageRoute) {
|
||||||
appRouteObserver.subscribe(this, route);
|
appRouteObserver.subscribe(this, route);
|
||||||
}
|
}
|
||||||
_syncCovered();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@@ -53,10 +46,14 @@ class _SkipBuildWhenCoveredState extends State<SkipBuildWhenCovered>
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didPushNext() => _syncCovered();
|
void didPushNext() {
|
||||||
|
if (!_covered) setState(() => _covered = true);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
void didPopNext() => _syncCovered();
|
void didPopNext() {
|
||||||
|
if (_covered) setState(() => _covered = false);
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
|||||||
@@ -57,6 +57,11 @@ migrate((app) => {
|
|||||||
required: false,
|
required: false,
|
||||||
onlyInt: true,
|
onlyInt: true,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
type: "bool",
|
||||||
|
name: "half_width",
|
||||||
|
required: false,
|
||||||
|
},
|
||||||
{
|
{
|
||||||
type: "json",
|
type: "json",
|
||||||
name: "label_ids",
|
name: "label_ids",
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
/// PocketBase migration: half_width on home_filter_widgets.
|
||||||
|
///
|
||||||
|
/// Apply after 1740000004 if that collection already exists.
|
||||||
|
migrate((app) => {
|
||||||
|
const col = app.findCollectionByNameOrId("home_filter_widgets");
|
||||||
|
col.fields.add({
|
||||||
|
type: "bool",
|
||||||
|
name: "half_width",
|
||||||
|
required: false,
|
||||||
|
});
|
||||||
|
app.save(col);
|
||||||
|
}, (app) => {
|
||||||
|
try {
|
||||||
|
const col = app.findCollectionByNameOrId("home_filter_widgets");
|
||||||
|
const field = col.fields.getByName("half_width");
|
||||||
|
if (field) {
|
||||||
|
col.fields.remove(field);
|
||||||
|
app.save(col);
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
});
|
||||||
@@ -22,6 +22,10 @@ void main() {
|
|||||||
expect(restored.showAmountOut, isTrue);
|
expect(restored.showAmountOut, isTrue);
|
||||||
expect(restored.showAmountIn, isFalse);
|
expect(restored.showAmountIn, isFalse);
|
||||||
expect(restored.showCount, isTrue);
|
expect(restored.showCount, isTrue);
|
||||||
|
expect(restored.halfWidth, isFalse);
|
||||||
|
|
||||||
|
final half = widget.copyWith(halfWidth: true);
|
||||||
|
expect(HomeFilterWidget.fromJson(half.toJson()).halfWidth, isTrue);
|
||||||
});
|
});
|
||||||
|
|
||||||
test('mergeHomeFilterWidgets unions by id with local wins', () {
|
test('mergeHomeFilterWidgets unions by id with local wins', () {
|
||||||
|
|||||||
Reference in New Issue
Block a user