feat(app): offline-кэш GET-запросов на дашборде — фаза 5

CacheInterceptor кэширует каждый успешный GET по путь+параметры в drift
(sqlite нативно, wasm+OPFS в браузере) и подменяет им сетевую ошибку;
провайдер отдаёт Cached<T>, экран показывает баннер «данные на …».
Контракт для остальных экранов — docs/ai/offline-cache.md.

flake.nix: libsecret/pkg-config для линуксовой сборки, jq/curl для
just app-web-assets (сборка sqlite3.wasm + drift_worker.js).
This commit is contained in:
Dmitry
2026-09-19 12:40:08 +03:00
parent 95cd6f176e
commit ffc5ed959a
21 changed files with 15852 additions and 60 deletions
+22 -18
View File
@@ -3,54 +3,58 @@ import 'package:fintracker_api/fintracker_api.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/api/api_client.dart';
import '../../core/cache/cached.dart';
final netWorthBreakdownProvider = FutureProvider.autoDispose<NetWorthBreakdown>((ref) async {
/// Every provider below returns `Cached<T>`, not `T`: `HomePage` reads
/// `.data` for the tiles and `.fetchedAt` (via `oldestFetch`) for the one
/// offline banner at the top. See `docs/ai/offline-cache.md`.
final netWorthBreakdownProvider = FutureProvider.autoDispose<Cached<NetWorthBreakdown>>((ref) async {
final r = await ref.watch(apiProvider).getNetworthApi().networthBreakdown();
return r.data!;
return r.cached;
});
/// Daily net worth for the last 365 days.
final netWorthSeriesProvider = FutureProvider.autoDispose<List<NetWorthDay>>((ref) async {
final netWorthSeriesProvider = FutureProvider.autoDispose<Cached<List<NetWorthDay>>>((ref) async {
final now = DateTime.now();
final r = await ref.watch(apiProvider).getNetworthApi().networthSeries(
from: now.subtract(const Duration(days: 365)),
to: now,
);
return r.data ?? const [];
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
});
/// The current (partial) month's cashflow, or null before any data exists.
final cashflowThisMonthProvider = FutureProvider.autoDispose<CashFlowMonth?>((ref) async {
final cashflowThisMonthProvider = FutureProvider.autoDispose<Cached<CashFlowMonth?>>((ref) async {
final r = await ref.watch(apiProvider).getCashflowApi().cashflowMonthly(months: 1);
final rows = r.data ?? const [];
return rows.isEmpty ? null : rows.last;
return Cached(rows.isEmpty ? null : rows.last, fetchedAt: r.extra['fetchedAt'] as DateTime?);
});
/// The last 12 months, for the income-vs-expense bar chart.
final cashflowLast12Provider = FutureProvider.autoDispose<List<CashFlowMonth>>((ref) async {
final cashflowLast12Provider = FutureProvider.autoDispose<Cached<List<CashFlowMonth>>>((ref) async {
final r = await ref.watch(apiProvider).getCashflowApi().cashflowMonthly(months: 12);
return r.data ?? const [];
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
});
final runwayProvider = FutureProvider.autoDispose<RunwayOut>((ref) async {
final runwayProvider = FutureProvider.autoDispose<Cached<RunwayOut>>((ref) async {
final r = await ref.watch(apiProvider).getCashflowApi().cashflowRunway();
return r.data!;
return r.cached;
});
/// When the metric tables were last rebuilt; null before the first refresh.
final metricsStatusProvider = FutureProvider.autoDispose<RefreshLogOut?>((ref) async {
final metricsStatusProvider = FutureProvider.autoDispose<Cached<RefreshLogOut?>>((ref) async {
try {
final r = await ref.watch(apiProvider).getMetricsApi().metricsStatus();
return r.data;
return r.cached;
} on DioException catch (e) {
if (e.response?.statusCode == 404) return null;
if (e.response?.statusCode == 404) return const Cached(null);
rethrow;
}
});
final dataQualityProvider = FutureProvider.autoDispose<List<DataQualityRow>>((ref) async {
final dataQualityProvider = FutureProvider.autoDispose<Cached<List<DataQualityRow>>>((ref) async {
final r = await ref.watch(apiProvider).getMetricsApi().metricsDataQuality();
return r.data ?? const [];
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
});
/// Every dashboard provider, refreshed together after a manual
@@ -68,12 +72,12 @@ void invalidateHomeProviders(WidgetRef ref) {
/// The investment side of the dashboard: one scope-wide summary, `all` by default.
/// Null when the ledger is empty, which is the normal state before a broker sync.
final portfolioSummaryHomeProvider = FutureProvider.autoDispose<SummaryOut?>((ref) async {
final portfolioSummaryHomeProvider = FutureProvider.autoDispose<Cached<SummaryOut?>>((ref) async {
try {
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsSummary();
return r.data;
return r.cached;
} on DioException catch (e) {
if (e.response?.statusCode == 404) return null;
if (e.response?.statusCode == 404) return const Cached(null);
rethrow;
}
});