feat(mobile): view and edit transaction splits
Problem
The web app can split a transaction into several entries with their own name, amount and category, and the API has had GET/POST/PATCH/DELETE /api/v1/transactions/:id/split for a while. The mobile app had no split support at all:
- A split parent and its children showed up as unrelated rows, so the same money looked like it was counted twice.
- Editing a split child from mobile failed with "Use the split editor", and mobile had no split editor.
- There was no way to split, re-split or unsplit from a phone.
What changed
All changes are in mobile/ and use the existing split API. There are no backend changes.
Transaction screen (TransactionEditScreen + new TransactionSplitSection)
- A split parent lists its children (name, category or "(uncategorized)", amount), with Edit split and Unsplit actions. Unsplit asks for confirmation first, as on the web.
- A split child shows "Part of split" with the same actions. Its own fields are read-only, because the API rejects direct edits to children.
- Any other synced transaction gets a Split transaction action.
Split editor (TransactionSplitScreen)
- Rows with name, amount and category. Rows can be added and removed (at least one row stays).
- A live Remaining indicator, red until the rows add up and green when they balance. Save is enabled only when the rows sum exactly to the original amount.
- Amounts use exact decimal math (
BigIntat the API's 4-decimal scale), not doubles, so 0.1 + 0.2 balances against 0.3. Inputs are limited to the currency's precision (USD 2, JPY 0, KWD 3), widened only if the stored parent amount is finer. Locale decimal separators are accepted, e.g.1 234,56in Swedish. - Amounts are entered as positive numbers in the original transaction's direction, and a minus sign marks a part that goes the other way. The app applies the parent's sign before sending, so income splits work without typing negatives.
- Editing pre-fills the rows from
amount_decimaland carries each child'sexcludedflag through the PATCH. The API replaces every child on update, so without this the flag would be silently dropped.
Transaction list
- Known split children are grouped under their parent. The parent is dimmed and gets a Split badge, matching the web's grouped view (
_split_parent_row). A child whose parent is not on screen gets a small split icon.
Offline and privacy
- Splits are online-only. The offline queue only replays creates and deletes, so split writes are refused offline rather than queued. Offline, the split section is read-only (cached splits stay visible), the editor shows an offline notice, and Save is disabled.
- After a split write, children the server destroyed are removed from the SQLite cache and the account is re-synced. This is needed because an account-scoped sync only upserts.
- Privacy mode masks every split amount: children, original amount, remaining, and the amount inputs, which are obscured.
Other
- New
TransactionSplitsService,TransactionSplitsProvider(registered inmain.dart, cleared alongside the other caches in Settings),SplitMathandgroupSplitEntriesutils. - en and sv strings (ARB plus the regenerated
app_localizations*.dart). - Notes in
docs/OFFLINE_FEATURES.mdanddocs/TECHNICAL_GUIDE.md.
Known limitation: the transactions index does not say which rows are split parents or children. The list can only group splits the app has already loaded, which happens when a transaction is opened, split, or edited. A follow-up could add split_parent / parent_transaction_id to the transaction JSON so the list can group every split on first load. I kept this PR mobile-only and did not change the API.
How it was tested
flutter analyze --no-fatal-infos: no new issues. The 3 existing infos inintro_screen_web.dartare unchanged.flutter test: 212 tests pass, 31 of them new.test/utils/split_math_test.dart: decimal parsing, including API strings and exponents; locale input; currency precision (USD/JPY/KWD); validation; exact remaining; formatting.test/utils/split_list_grouping_test.dart: children placed under their parent in split order, unknown rows untouched, and orphan children.test/services/transaction_splits_service_test.dart: GET parse, 404 means not split, POST/PATCH payloads (includingexcluded), 422 message surfaced, and DELETE.test/widgets/transaction_split_test.dart: the remaining indicator and Save gating; the POST payload for expense and income signs; the JPY precision error; edit pre-fill plus remove/add row plus PATCH; privacy masking; offline Save disabled; the detail section for parent, child and unsplit cases; the unsplit confirm flow and DELETE; offline read-only.
dart formaton all new files and on the two touched files that were already formatted. The other touched files are not dart-formatted upstream, so I left their existing lines alone.- Run locally with Flutter 3.32.4, the same version as
flutter-build.yml. - Not run:
flutter build apkand an on-device check. No Android SDK or JDK was available on the build machine (linux-arm64). CI's Build Android APK job covers the APK build.
Screenshots (rendered from widget tests with the bundled Geist fonts): the editor unbalanced, the editor balanced, and a split parent on the transaction screen.
Summary by CodeRabbit
- New Features
- Split transactions into categorized child entries, edit existing splits, or remove a split to restore the original transaction.
- View split details and amounts in the transaction list, with split children grouped under their parent.
- Split amounts must match the original total and follow currency precision rules; amounts remain masked in privacy mode.
- Added English and Swedish translations for split transaction features and messages.
- Bug Fixes
- Cached split details remain visible offline, while split changes are unavailable until connectivity returns.
- Transaction data refreshes after split changes so removed child entries no longer appear.
- Documentation
- Added documentation for split behavior, offline limitations, and supported API operations.