← Back to Pull requests

feat(mobile): budgets screen #4426

Closed
unknown closed this pull request without merging on Oct 25, 2026 05:30 UTC
View on GitHub
unknown unknown commented on Oct 22, 2026 00:43 UTC
Author

feat(mobile): budgets screen

(Paste as the PR #4426 body, above the CodeRabbit summary block.)

---

Replaces #4324, which GitHub closed after an accidental force-push left its branch empty (a PR in that state can't be reopened). Earlier review history is on #4324; this description is self-contained.

Problem

The mobile app can't show budgets. To compare this month's spending with the plan, users have to open the web app, even though the read-only budgets API (GET /api/v1/budgets, GET /api/v1/budget_categories) exists.

What changed

A Budgets screen, opened from More, mirrors the web budgets page:

  • Month navigation. It opens on the budget period the server marks current (so families with a custom month start land on their real period), and Next goes up to two years ahead, like Budget.latest_valid_budget_start_date. The header uses the budget's server name.

  • Summary card: budgeted, actual and remaining spending, an overall progress bar, and actual vs. expected income.

  • One progress bar per category line, subcategories nested under their parent: "spent of budget" and the amount left or over, "+X rolled over", and "Shared budget" for subcategories without their own limit (red when the shared pool is overspent).

  • Near-limit (90%+) and over-budget badges, and an All / Over budget (n) filter when anything is over. Line visibility follows the model helpers (budgeted?, over_budget?, near_limit?, visible_on_track?); a budget that isn't initialized lists every line, as on the web.

  • Tapping a line opens its transactions for the budget period (a parent includes its subcategories), paged through GET /api/v1/transactions with category_ids[], start_date and end_date. TransactionsService.getTransactions gains these three optional params (identical to the same change in #4428); existing callers are unchanged.

  • Several budgets in one month (household, personal, shared): chips switch between them, reusing the month's budget list.

  • Privacy mode masks every amount, and progress bars draw only the empty track with no percentage in their semantics.

  • Offline: a month loaded earlier in the session stays visible with a note; otherwise an offline state with Try again. A failed refresh keeps the loaded month on screen with a "Couldn't refresh" banner. Empty and error states cover no budget for the month, a budget with no amounts yet, an expired session (401, including when switching budgets) and a failed load. Raw server or network error text is logged, never shown.

  • en and sv strings (ARB + regenerated localizations).
  • Layers: models/budget.dart, services/budgets_service.dart (injectable http.Client), providers/budgets_provider.dart (owned by the screen, so nothing survives a sign-out; stale and post-dispose responses are ignored), screens/budgets_screen.dart, screens/budget_category_transactions_screen.dart, widgets/budget_*, using SureCard, SureSegmentedControl, SureChip, SureButton and SureColors tokens.

    API notes (no backend changes in this PR):

  • The index endpoints omit derived amounts, so a month is built from the budgets list, the budget show request and one budget_categories/:id request per line, six at a time; months are cached for the session. A line whose detail is gone (404) keeps its budgeted amount; any other failure fails the month so a partial month is never cached. Actuals in the index (or a bulk endpoint) would make this one request; happy to send that as a follow-up.

  • Budgets exist only for months opened on the web (Budget.find_or_bootstrap); other months show "No budget for {month}". Lines for categories created after a budget was bootstrapped also need the web (or an API-side bootstrap).

  • The payload doesn't say who owns a budget, so chips read "Budget 1 / Budget 2".

  • The web's synthetic "Uncategorized" line isn't in the API and can't be derived exactly on the client, so it isn't shown.

  • Drilldown scoping: it filters by category and the budget's dates. #4423 adds budget_id (owner scope, excluded kinds) and excluded=false to the transactions index; the drilldown will use them once it merges.
  • How it was tested

  • Flutter 3.32.4 (same as CI). flutter analyze: only the 3 pre-existing infos in intro_screen_web.dart.

  • flutter test: 243 passed, including:

  • - test/models/budget_test.dart: parsing, over/near-limit and visibility rules, rollover, shared pools (ring-fenced siblings and their rollover), grouping.
    - test/services/budgets_service_test.dart: query params, show/index parsing, 401 and errors, transaction filters.
    - test/providers/budgets_provider_test.dart: month assembly, session cache, server current period vs device date, custom month start, month change during a load, list reuse only for its own month, pagination safety stop, failed refresh keeps the month, dispose during a load, 404 vs network failure on a line, budget switching without refetching the list, 401, offline.
    - test/screens/budgets_screen_test.dart and budget_category_transactions_screen_test.dart: totals, nesting and badges, over-budget filter, privacy, Swedish month formatting, empty state, navigation, drilldown ids, refresh-failed banner, session-expired states, retry reloading page one.
  • New files pass dart format; generated l10n keeps the repo's format.

  • No APK build (no Android SDK available); CI's Android job covers it.
  • Screenshots: light, dark and light with privacy mode (attached on #4324).

    <!-- This is an auto-generated comment: release notes by coderabbit.ai -->
    <!-- coderabbit-ai-generated:v1 -->

    Summary by CodeRabbit

  • New Features

  • - Added a Budgets screen with monthly navigation, budget selection, spending summaries, category progress and statuses, rollover details, and an over-budget filter.
    - Added paginated transaction views for budget categories, with date ranges, refresh, and retry options.
    - Added Budgets access from the More menu.
    - Added cached budget access while offline, along with loading, authentication, empty, and error states.
    - Amounts respect privacy settings in budget and transaction views.
  • Localization

  • - Added English and Swedish translations for budgets, categories, transactions, and related statuses.
  • Bug Fixes

  • - Added category and date filters to transaction loading.
    <!-- end of auto-generated comment: release notes by coderabbit.ai -->

    Diff: 650 lines (+487 / -163) across 8 files Reviewer: bhargavmehta01 Review duration: 4607m
    All Vouch review confidence checks passed
    Residual risk 0.22 = Change Risk (0.52) × (1 − Review Confidence (0.57)). Review depth and reviewer attention state are adequate.
    Model 1 · Change Risk (XGBoost)
    Score: 0.52 · 650 lines diff across 8 files
    0.52
    Model 2 · Review Depth (DistilBERT)
    Depth Score: 0.17 · 1 substantive comment(s)
    0.17
    Model 3 · Review Timing & Attention
    Session adequacy: 100% · Reviewer familiarity: 35%
    56%
    Bedrock Claude 3 · Risk Narration
    (disconnected)
    Groq
    Groq Risk Narration
    AWS Bedrock is currently disconnected. Generate high-confidence PR triage narration on-demand using Groq.
    Model 1 · Change Risk Attribution
    SHAP Weights
    Diff Size diff_size
    0.388
    Shallow Review Depth shallow_review_depth
    0.289
    Real PR Conversation Timeline
    1 comments
    "Review active on #4426"
    general weight: 0.35
    Assignees
    Unassigned
    Labels
    risk: low confidence: 56.8% reviewed
    Vouch Risk Breakdown
    AI-powered review risk analysis
    Change Risk
    Change Risk · Model 1 (XGBoost)
    Predicted defect probability (0.00–1.00) based on diff churn, modified sensitive files, and author risk history.
    Score: 52% (MEDIUM) · Higher = larger blast radius
    52%
    Review Confidence
    Review Confidence · Models 2 & 3
    Scrutiny score (0.00–1.00) combining DistilBERT semantic review depth with reviewer familiarity and session dwell time.
    Score: 56.8% · Lower = rushed or shallow review
    56.8%
    Residual Risk
    Residual Risk · Core Equation
    Residual = Change × (1 − Confidence)
    Unmitigated risk surviving review. ≥ 0.65 triggers an automated re-queue to protect production.
    Score: 22.5% · Safe to merge
    22.5%