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:
Dmitry
2026-09-19 14:00:13 +03:00
parent ffc5ed959a
commit 7b419f4188
39 changed files with 388 additions and 186 deletions
+6 -1
View File
@@ -5,11 +5,13 @@ import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:go_router/go_router.dart';
import '../../core/cache/cached.dart';
import '../../core/theme/chart_colors.dart';
import '../../core/utils/ru_date.dart';
import '../../core/widgets/async_value_view.dart';
import '../../core/widgets/empty_state.dart';
import '../../core/widgets/money_text.dart';
import '../../core/widgets/stale_banner.dart';
import 'providers.dart';
const _incomeColor = ChartColors.income;
@@ -26,6 +28,7 @@ class CashflowPage extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final monthly = ref.watch(cashflowMonthly24Provider);
final stale = oldestFetch([monthly.valueOrNull?.fetchedAt]);
return Scaffold(
appBar: AppBar(title: const Text('Потоки')),
@@ -34,7 +37,8 @@ class CashflowPage extends ConsumerWidget {
child: AsyncValueView(
value: monthly,
onRetry: () => ref.invalidate(cashflowMonthly24Provider),
data: (rows) {
data: (cached) {
final rows = cached.data;
if (rows.isEmpty) {
return ListView(
children: const [
@@ -48,6 +52,7 @@ class CashflowPage extends ConsumerWidget {
return ListView(
padding: const EdgeInsets.all(16),
children: [
if (stale != null) StaleBanner(fetchedAt: stale),
const _Legend(),
const SizedBox(height: 8),
SizedBox(
+4 -3
View File
@@ -2,9 +2,10 @@ 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';
/// The last 24 months, oldest first (as the API returns them).
final cashflowMonthly24Provider = FutureProvider.autoDispose<List<CashFlowMonth>>((ref) async {
/// The last 24 months, oldest first (as the API returns them). See `docs/ai/offline-cache.md`.
final cashflowMonthly24Provider = FutureProvider.autoDispose<Cached<List<CashFlowMonth>>>((ref) async {
final r = await ref.watch(apiProvider).getCashflowApi().cashflowMonthly(months: 24);
return r.data ?? const [];
return Cached(r.data ?? const [], fetchedAt: r.extra['fetchedAt'] as DateTime?);
});