some issues fixed

This commit is contained in:
davmar
2026-09-11 12:31:07 +02:00
parent 2e40786bcd
commit 40366f0708
9 changed files with 416 additions and 127 deletions
+89 -22
View File
@@ -474,7 +474,19 @@ class _OverviewScreenState extends State<OverviewScreen> {
),
);
},
onMonthTap: (month) => _openPeriod(context, month),
onMonthTap: (month, {labelId, flow}) => _openPeriod(
context,
month,
labelId: labelId,
labelIds: {
for (final id in favourite.labelIds) id,
},
flow: flow ??
(favourite.metric == OverviewMetricMode.labels
? favourite.flow
: null),
periodMode: favourite.period,
),
);
}
@@ -590,7 +602,13 @@ class _OverviewScreenState extends State<OverviewScreen> {
),
);
},
onMonthTap: (month) => _openPeriod(context, month),
onMonthTap: (month, {labelId, flow}) => _openPeriod(
context,
month,
labelId: labelId,
flow: flow ??
(_metric == OverviewMetricMode.labels ? _labelFlow : null),
),
),
const SizedBox(height: 14),
if (_metric == OverviewMetricMode.flow) ...[
@@ -739,22 +757,28 @@ class _OverviewScreenState extends State<OverviewScreen> {
BuildContext context,
DateTime period, {
String? labelId,
Set<String>? labelIds,
TxFlowFilter? flow,
OverviewPeriodMode? periodMode,
}) {
final yearly = _period == OverviewPeriodMode.yearly;
final mode = periodMode ?? _period;
final yearly = mode == OverviewPeriodMode.yearly;
final initial = yearly ? DateTime(period.year, 12) : period;
final labelIds = labelId != null
final resolvedLabelIds = labelId != null
? {labelId}
: {
// Open with the same labels currently shown on the chart.
for (final id in _includedLabelIds) id,
};
: (labelIds ??
{
// Open with the same labels currently shown on the chart.
for (final id in _includedLabelIds) id,
});
Navigator.of(context).push(
MaterialPageRoute<void>(
builder: (_) => TransactionsScreen(
initialMonth: initial,
initialLabelIds: labelIds,
initialLabelIds: resolvedLabelIds,
initialLabelMatch: LabelMatchMode.or,
initialSearchInMonthOnly: !yearly && labelIds.isNotEmpty,
initialFlow: flow,
initialSearchInMonthOnly: !yearly && resolvedLabelIds.isNotEmpty,
initialYear: yearly ? period.year : null,
),
),
@@ -1182,7 +1206,11 @@ class _ChartCard extends StatelessWidget {
final int? includedLabelCount;
final int availableLabelCount;
final void Function(TxLabel label) onLabelTap;
final void Function(DateTime month) onMonthTap;
final void Function(
DateTime month, {
String? labelId,
TxFlowFilter? flow,
}) onMonthTap;
final ValueChanged<OverviewPeriodMode>? onPeriodModeChanged;
final VoidCallback? onEdit;
@@ -1277,7 +1305,7 @@ class _ChartCard extends StatelessWidget {
runSpacing: 2,
alignment: WrapAlignment.end,
children: [
for (final row in labelSpend.take(compact ? 3 : 5))
for (final row in labelSpend.take(6))
GestureDetector(
onTap: () => onLabelTap(row.label),
child: _LegendDot(
@@ -1286,7 +1314,7 @@ class _ChartCard extends StatelessWidget {
compact: compact,
),
),
if (labelSpend.length > (compact ? 3 : 5))
if (labelSpend.length > 6)
_LegendDot(
color: colors.outline,
label: 'Other',
@@ -1529,6 +1557,7 @@ class _ChartCard extends StatelessWidget {
monthly: monthly,
currency: currency,
period: period,
onMonthTap: onMonthTap,
)
: _LabelMonthBars(
months: months,
@@ -1554,12 +1583,18 @@ class _FlowBars extends StatelessWidget {
required this.monthly,
required this.currency,
required this.period,
required this.onMonthTap,
});
final List<DateTime> months;
final Map<DateTime, _MonthBucket> monthly;
final String currency;
final OverviewPeriodMode period;
final void Function(
DateTime month, {
String? labelId,
TxFlowFilter? flow,
}) onMonthTap;
@override
Widget build(BuildContext context) {
@@ -1594,6 +1629,19 @@ class _FlowBars extends StatelessWidget {
maxY: safeMax,
groupsSpace: period == OverviewPeriodMode.yearly ? 16 : 10,
barTouchData: BarTouchData(
touchCallback: (event, response) {
if (event is! FlTapUpEvent) return;
final spot = response?.spot;
if (spot == null) return;
final index = spot.touchedBarGroupIndex;
if (index < 0 || index >= months.length) return;
final rodIndex = spot.touchedRodDataIndex;
// Rods: 0 = expense, 1 = income.
final flow = rodIndex == 1
? TxFlowFilter.income
: TxFlowFilter.expense;
onMonthTap(months[index], flow: flow);
},
touchTooltipData: BarTouchTooltipData(
getTooltipItem: (group, groupIndex, rod, rodIndex) {
final month = months[group.x.toInt()];
@@ -1709,7 +1757,7 @@ class _LabelMonthBars extends StatelessWidget {
required this.onMonthTap,
});
static const _maxSeriesLabels = 5;
static const _maxSeriesLabels = 6;
final List<DateTime> months;
final List<_LabelSpend> labelSpend;
@@ -1718,7 +1766,11 @@ class _LabelMonthBars extends StatelessWidget {
final OverviewPeriodMode period;
final LabelChartBarStyle barStyle;
final bool invertChart;
final void Function(DateTime month) onMonthTap;
final void Function(
DateTime month, {
String? labelId,
TxFlowFilter? flow,
}) onMonthTap;
double _plot(double value) => invertChart ? -value : value;
@@ -1805,12 +1857,12 @@ class _LabelMonthBars extends StatelessWidget {
final rodWidth = stacked
? (period == OverviewPeriodMode.yearly ? 18.0 : 14.0)
: period == OverviewPeriodMode.yearly
? (seriesCount <= 3 ? 12.0 : 8.0)
? (seriesCount <= 3 ? 12.0 : seriesCount <= 6 ? 8.0 : 6.0)
: (seriesCount <= 3
? 7.0
: seriesCount <= 5
? 5.0
: 4.0);
: seriesCount <= 6
? 4.5
: 3.5);
List<BarChartRodData> rodsFor(DateTime month) {
final bucket =
@@ -1896,9 +1948,24 @@ class _LabelMonthBars extends StatelessWidget {
barTouchData: BarTouchData(
touchCallback: (event, response) {
if (event is! FlTapUpEvent) return;
final index = response?.spot?.touchedBarGroupIndex;
if (index == null || index < 0 || index >= months.length) return;
onMonthTap(months[index]);
final spot = response?.spot;
if (spot == null) return;
final index = spot.touchedBarGroupIndex;
if (index < 0 || index >= months.length) return;
String? labelId;
if (stacked) {
final stackIdx = spot.touchedStackItemIndex;
if (stackIdx >= 0 && stackIdx < topLabels.length) {
labelId = topLabels[stackIdx].label.id;
}
} else {
final rodIdx = spot.touchedRodDataIndex;
if (rodIdx >= 0 && rodIdx < topLabels.length) {
labelId = topLabels[rodIdx].label.id;
}
// Last rod may be "Other" — open month with chart labels only.
}
onMonthTap(months[index], labelId: labelId);
},
touchTooltipData: BarTouchTooltipData(
getTooltipItem: (group, groupIndex, rod, rodIndex) {