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:
@@ -1,9 +1,11 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../../core/cache/cached.dart';
|
||||
import '../../core/utils/json.dart';
|
||||
import '../../core/widgets/async_value_view.dart';
|
||||
import '../../core/widgets/empty_state.dart';
|
||||
import '../../core/widgets/stale_banner.dart';
|
||||
import 'data/goals_api.dart';
|
||||
import 'goal_card.dart';
|
||||
import 'goal_edit_dialog.dart';
|
||||
@@ -78,6 +80,13 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
final goals = ref.watch(goalsProvider);
|
||||
// Every card's own progress fetch counts toward the one banner too — a fresh list with a
|
||||
// stale progress card is still an offline dashboard, just not a visibly empty one.
|
||||
final goalIds = [for (final g in goals.valueOrNull?.data ?? const <Goal>[]) g.id];
|
||||
final stale = oldestFetch([
|
||||
goals.valueOrNull?.fetchedAt,
|
||||
for (final id in goalIds) ref.watch(goalProgressProvider(id)).valueOrNull?.fetchedAt,
|
||||
]);
|
||||
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
@@ -105,12 +114,14 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
child: AsyncValueView(
|
||||
value: goals,
|
||||
onRetry: () => ref.invalidate(goalsProvider),
|
||||
data: (all) {
|
||||
data: (cached) {
|
||||
final all = cached.data;
|
||||
final rows = _showArchived ? all : all.where((g) => !g.archived).toList();
|
||||
if (rows.isEmpty) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
children: [
|
||||
if (stale != null) StaleBanner(fetchedAt: stale),
|
||||
const SizedBox(height: 48),
|
||||
EmptyState(
|
||||
icon: Icons.flag_outlined,
|
||||
@@ -125,6 +136,7 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.fromLTRB(16, 16, 16, 88),
|
||||
children: [
|
||||
if (stale != null) StaleBanner(fetchedAt: stale),
|
||||
for (final g in rows)
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(bottom: 12),
|
||||
|
||||
Reference in New Issue
Block a user