feat(app): экраны импорта отчётов, целей, доходов, ребалансировки, налогов и бенчмарков

Импорт (/imports, /instruments/pending) и фаза 4 (/goals, /income,
/rebalance, /tax, аналитика-хаб с benchmarks_card) — по
docs/ai/import-contract.md и docs/ai/phase4-contract.md. file_picker для
загрузки отчёта.
This commit is contained in:
Dmitry
2026-09-19 10:44:38 +03:00
parent 15f5812ea4
commit b69bb4a0c9
52 changed files with 7404 additions and 13 deletions
+144
View File
@@ -0,0 +1,144 @@
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../core/utils/json.dart';
import '../../core/widgets/async_value_view.dart';
import '../../core/widgets/empty_state.dart';
import 'data/goals_api.dart';
import 'goal_card.dart';
import 'goal_edit_dialog.dart';
import 'providers.dart';
/// Цели: the goal list, each card carrying its server-computed progress.
class GoalsPage extends ConsumerStatefulWidget {
const GoalsPage({super.key});
@override
ConsumerState<GoalsPage> createState() => _GoalsPageState();
}
class _GoalsPageState extends ConsumerState<GoalsPage> {
bool _showArchived = false;
void _snack(String message) =>
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
Future<void> _create() async {
final goal = await showDialog<Goal>(
context: context,
builder: (_) => const GoalEditDialog(),
);
if (goal == null) return;
try {
await ref.read(goalsApiProvider).create(goal);
if (!mounted) return;
invalidateGoals(ref);
} catch (e) {
if (mounted) _snack(apiErrorMessage(e));
}
}
Future<void> _edit(Goal goal) async {
final updated = await showDialog<Goal>(
context: context,
builder: (_) => GoalEditDialog(initial: goal),
);
if (updated == null) return;
try {
await ref.read(goalsApiProvider).patch(goal.id, updated.toJson());
if (!mounted) return;
invalidateGoals(ref);
} catch (e) {
if (mounted) _snack(apiErrorMessage(e));
}
}
Future<void> _delete(Goal goal) async {
final confirmed = await showDialog<bool>(
context: context,
builder: (ctx) => AlertDialog(
title: const Text('Удалить цель?'),
content: Text('«${goal.name}» будет удалена безвозвратно.'),
actions: [
TextButton(onPressed: () => Navigator.of(ctx).pop(false), child: const Text('Отмена')),
FilledButton(onPressed: () => Navigator.of(ctx).pop(true), child: const Text('Удалить')),
],
),
);
if (confirmed != true) return;
try {
await ref.read(goalsApiProvider).delete(goal.id);
if (!mounted) return;
invalidateGoals(ref);
} catch (e) {
if (mounted) _snack(apiErrorMessage(e));
}
}
@override
Widget build(BuildContext context) {
final goals = ref.watch(goalsProvider);
return Scaffold(
appBar: AppBar(
title: const Text('Цели'),
actions: [
IconButton(
tooltip: _showArchived ? 'Скрыть архив' : 'Показать архив',
icon: Icon(_showArchived ? Icons.inventory_2 : Icons.inventory_2_outlined),
onPressed: () => setState(() => _showArchived = !_showArchived),
),
IconButton(
tooltip: 'Обновить',
icon: const Icon(Icons.refresh),
onPressed: () => invalidateGoals(ref),
),
],
),
floatingActionButton: FloatingActionButton.extended(
onPressed: _create,
icon: const Icon(Icons.add),
label: const Text('Новая цель'),
),
body: RefreshIndicator(
onRefresh: () async => invalidateGoals(ref),
child: AsyncValueView(
value: goals,
onRetry: () => ref.invalidate(goalsProvider),
data: (all) {
final rows = _showArchived ? all : all.where((g) => !g.archived).toList();
if (rows.isEmpty) {
return ListView(
padding: const EdgeInsets.all(16),
children: [
const SizedBox(height: 48),
EmptyState(
icon: Icons.flag_outlined,
message: all.isEmpty
? 'Целей пока нет.\nЦель — это сумма и (необязательно) дата; '
'прогноз считает сервер по доходности или по взносам.'
: 'Все цели в архиве — включите показ архива.',
),
],
);
}
return ListView(
padding: const EdgeInsets.fromLTRB(16, 16, 16, 88),
children: [
for (final g in rows)
Padding(
padding: const EdgeInsets.only(bottom: 12),
child: GoalCard(
goal: g,
onEdit: () => _edit(g),
onDelete: () => _delete(g),
),
),
],
);
},
),
),
);
}
}