feat(mobile): cash flow and spending by category
Closed
BH
1mo ago+0+0+0123456789-0-0-0123456789
Problem
The mobile app shows balances and transactions, but nothing tells you where the money went. The web dashboard has the cash flow Sankey and the spending-by-category donut, and GET /api/v1/cash_flow already returns those numbers. The mobile app doesn't use that endpoint yet.
What changed
A new Cash Flow screen, opened from More (alongside Account Calendar and Recent Transactions):
- Period selector with the web
Periodpresets: This month, Last month, Last 30 days, Last 90 days, Year to date, Last 365 days. Each one is sent asview=sankey&start_date=…&end_date=…, so every period goes through the same server aggregation as the web Sankey. - Summary: income, expenses, net savings and savings rate.
- By category: an Expenses/Income toggle, a donut chart, and a ranked list showing each category's amount and share. Colors are the user's category colors.
- Drill-down: tapping a category lists its transactions for the period, including its subcategories and refunds. This uses
GET /api/v1/transactionswithstart_date,end_dateandcategory_ids[], with paging. Uncategorized is listed but can't be tapped, because the transactions API can't filter on a null category. - Privacy mode masks amounts and percentage shares. Only the chart's proportions stay visible.
- Offline/errors: the report is calculated on the server, so it needs a connection. If a refresh fails, the last report stays on screen with an "Outdated" badge, the same way the net worth card handles it. With nothing loaded, the screen shows an error state with a retry button and an offline message.
- Strings: English and Swedish ARB strings, with the generated localizations regenerated.
Implementation notes:
CashFlowReport.fromJsonturns the Sankey nodes and links into per-side root categories, with subcategories folded in as children. No totals are recalculated on the client.TransactionsService.getTransactionsgets three optional filters:startDate,endDateandcategoryIds. Existing callers are unchanged.- No new dependency. The app has no charting package, and one donut didn't justify adding one. The chart is a small
CustomPainter(widgets/cash_flow_donut_chart.dart), like the existing balance sparkline. - The UI uses the existing DS pieces:
SureCard,SureChip,SureSegmentedControl,SureListGroup/SureListRow,MoneyText,MoneyMaskerand theSureColors/SureSpacingtokens.
Not included (possible follow-ups): the Sankey diagram itself, the account grouping (group_by=account), custom date ranges, and the family's custom month start for "Last month". Period dates are computed in the device's time zone.
How it was tested
flutter analyze --no-fatal-infos(Flutter 3.32.4, same as CI): only the 3 infos that are already on main inintro_screen_web.dart. No new issues.flutter test: all 204 tests pass, 23 of them new:test/models/cash_flow_test.dart: period ranges (including the year wrap), Sankey parsing, ranking, subcategory folding, Uncategorized handling, savings rate.test/services/cash_flow_service_test.dart: query params, 401/422/network errors, and thecategory_ids[]transactions filter.test/widgets/cash_flow_screen_test.dart: summary values, the income/expense toggle, period switching and caching, privacy masking, drill-down navigation and request, Uncategorized not tappable, the error state, Outdated after a failed refresh, and the More screen entry.
- Screenshots (light/dark, expenses/income) were rendered from the widget tree with the bundled Geist font.
- Not built as an APK or run on a device: there was no Android SDK in my environment. CI's
flutter build apk --debugwill cover the build.
Summary by CodeRabbit
-
New Features
- Added a Cash Flow report with six selectable periods, income and expense totals, net savings, savings rate, and category breakdowns.
- Added donut charts and category drill-down to view transactions, including subcategories, for the selected period.
- Added loading, empty, offline, outdated, and error states with refresh and retry options.
- Added Cash Flow navigation and English and Swedish text.
- Added date and category filtering for Cash Flow transactions.
-
Privacy
- Monetary values are masked in Cash Flow reports and category transaction views when privacy settings require it.