feat(app): offline-кэш на остальных экранах — фаза 5
accounts, cashflow, categories, goals, income, portfolio (+instrument), rebalance, tax, rules переведены на Cached<T> по контракту docs/ai/offline-cache.md. Общие/второстепенные селекторы (scopesProvider, categoriesListProvider и т.п.) оставлены как есть — не основной контент экрана. sync_page.dart и settings_page.dart не тронуты (первый — заменён health-page отдельно, второй — чистые действия без списка для баннера).
This commit is contained in:
@@ -2,6 +2,7 @@ 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';
|
||||
import 'benchmarks_card.dart' show benchmarkRowsProvider;
|
||||
|
||||
/// The reporting unit every portfolio screen is scoped to: `all`, `account:<id>` or
|
||||
@@ -9,37 +10,42 @@ import 'benchmarks_card.dart' show benchmarkRowsProvider;
|
||||
/// and the instrument card — three screens showing different scopes would be a trap.
|
||||
final scopeProvider = StateProvider<String>((ref) => 'all');
|
||||
|
||||
/// A small cross-screen selector (Портфель, Доходы, Налоги, the goal dialog), not a screen's
|
||||
/// own primary read — left un-cached per `docs/ai/offline-cache.md`. The underlying `GET`
|
||||
/// still gets served from the shared cache transparently on a network failure; this provider
|
||||
/// just does not surface `fetchedAt` for a banner.
|
||||
final scopesProvider = FutureProvider.autoDispose<List<ScopeOut>>((ref) async {
|
||||
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsScopes();
|
||||
return r.data ?? const [];
|
||||
});
|
||||
|
||||
final portfolioSummaryProvider = FutureProvider.autoDispose<SummaryOut>((ref) async {
|
||||
/// See `docs/ai/offline-cache.md`.
|
||||
final portfolioSummaryProvider = FutureProvider.autoDispose<Cached<SummaryOut>>((ref) async {
|
||||
final scope = ref.watch(scopeProvider);
|
||||
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsSummary(scope: scope);
|
||||
return r.data!;
|
||||
return r.cached;
|
||||
});
|
||||
|
||||
final holdingsProvider = FutureProvider.autoDispose<List<HoldingOut>>((ref) async {
|
||||
final holdingsProvider = FutureProvider.autoDispose<Cached<List<HoldingOut>>>((ref) async {
|
||||
final scope = ref.watch(scopeProvider);
|
||||
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsHoldings(scope: scope);
|
||||
return r.data ?? const [];
|
||||
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
});
|
||||
|
||||
final portfolioReturnsProvider = FutureProvider.autoDispose<List<ReturnsOut>>((ref) async {
|
||||
final portfolioReturnsProvider = FutureProvider.autoDispose<Cached<List<ReturnsOut>>>((ref) async {
|
||||
final scope = ref.watch(scopeProvider);
|
||||
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsReturns(scope: scope);
|
||||
return r.data ?? const [];
|
||||
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
});
|
||||
|
||||
final allocationProvider = FutureProvider.autoDispose<List<AllocationBucket>>((ref) async {
|
||||
final allocationProvider = FutureProvider.autoDispose<Cached<List<AllocationBucket>>>((ref) async {
|
||||
final scope = ref.watch(scopeProvider);
|
||||
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsAllocation(scope: scope);
|
||||
return r.data ?? const [];
|
||||
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
});
|
||||
|
||||
/// Daily portfolio value for the last year, for the chart on Позиции.
|
||||
final valueSeriesProvider = FutureProvider.autoDispose<List<ValueDay>>((ref) async {
|
||||
final valueSeriesProvider = FutureProvider.autoDispose<Cached<List<ValueDay>>>((ref) async {
|
||||
final scope = ref.watch(scopeProvider);
|
||||
final now = DateTime.now();
|
||||
final r = await ref.watch(apiProvider).getAnalyticsApi().analyticsValueSeries(
|
||||
@@ -47,17 +53,17 @@ final valueSeriesProvider = FutureProvider.autoDispose<List<ValueDay>>((ref) asy
|
||||
from: now.subtract(const Duration(days: 365)),
|
||||
to: now,
|
||||
);
|
||||
return r.data ?? const [];
|
||||
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
|
||||
});
|
||||
|
||||
final instrumentProvider =
|
||||
FutureProvider.autoDispose.family<InstrumentDetail, int>((ref, instrumentId) async {
|
||||
FutureProvider.autoDispose.family<Cached<InstrumentDetail>, int>((ref, instrumentId) async {
|
||||
final scope = ref.watch(scopeProvider);
|
||||
final r = await ref
|
||||
.watch(apiProvider)
|
||||
.getInstrumentsApi()
|
||||
.instrumentsGet(instrumentId: instrumentId, scope: scope);
|
||||
return r.data!;
|
||||
return r.cached;
|
||||
});
|
||||
|
||||
/// Every portfolio provider, refreshed together after a metrics rebuild or a pull-to-refresh.
|
||||
|
||||
Reference in New Issue
Block a user