style(app): остальные экраны под новый визуальный язык и форматирование
Доходы, ребалансировка, налоги, импорт, цели, здоровье данных, правила, транзакции, категории, cashflow, pending: новые виджеты и токены темы, dart format. Тесты подстроены под новые модели.
This commit is contained in:
@@ -40,33 +40,33 @@ class Goal {
|
||||
/// The create/patch body. `id` is never sent; `null` fields are omitted so a PATCH that
|
||||
/// touches one field does not blank the rest.
|
||||
Map<String, dynamic> toJson() => {
|
||||
'name': name,
|
||||
'scope': scope,
|
||||
'target_amount': targetAmount,
|
||||
'currency': currency,
|
||||
'target_date': ?_isoDate(targetDate),
|
||||
'monthly_contribution': ?monthlyContribution,
|
||||
'note': ?note,
|
||||
'archived': archived,
|
||||
};
|
||||
'name': name,
|
||||
'scope': scope,
|
||||
'target_amount': targetAmount,
|
||||
'currency': currency,
|
||||
'target_date': ?_isoDate(targetDate),
|
||||
'monthly_contribution': ?monthlyContribution,
|
||||
'note': ?note,
|
||||
'archived': archived,
|
||||
};
|
||||
|
||||
static Goal fromJson(Map<String, dynamic> json) => Goal(
|
||||
id: asInt(json['id']) ?? 0,
|
||||
name: asString(json['name']) ?? 'Без названия',
|
||||
scope: asString(json['scope']) ?? 'all',
|
||||
targetAmount: asString(json['target_amount']) ?? '0',
|
||||
currency: asString(json['currency']) ?? 'RUB',
|
||||
targetDate: asDate(json['target_date']),
|
||||
monthlyContribution: asString(json['monthly_contribution']),
|
||||
note: asString(json['note']),
|
||||
archived: asBool(json['archived']),
|
||||
);
|
||||
id: asInt(json['id']) ?? 0,
|
||||
name: asString(json['name']) ?? 'Без названия',
|
||||
scope: asString(json['scope']) ?? 'all',
|
||||
targetAmount: asString(json['target_amount']) ?? '0',
|
||||
currency: asString(json['currency']) ?? 'RUB',
|
||||
targetDate: asDate(json['target_date']),
|
||||
monthlyContribution: asString(json['monthly_contribution']),
|
||||
note: asString(json['note']),
|
||||
archived: asBool(json['archived']),
|
||||
);
|
||||
|
||||
static String? _isoDate(DateTime? d) => d == null
|
||||
? null
|
||||
: '${d.year.toString().padLeft(4, '0')}-'
|
||||
'${d.month.toString().padLeft(2, '0')}-'
|
||||
'${d.day.toString().padLeft(2, '0')}';
|
||||
'${d.month.toString().padLeft(2, '0')}-'
|
||||
'${d.day.toString().padLeft(2, '0')}';
|
||||
}
|
||||
|
||||
class GoalProgress {
|
||||
@@ -106,17 +106,17 @@ class GoalProgress {
|
||||
bool get isUnreachable => projectedDate == null && basis != 'none';
|
||||
|
||||
static GoalProgress fromJson(Map<String, dynamic> json) => GoalProgress(
|
||||
goalId: asInt(json['goal_id']) ?? 0,
|
||||
asOf: asDate(json['as_of']),
|
||||
currentValueRub: asString(json['current_value_rub']),
|
||||
targetAmountRub: asString(json['target_amount_rub']),
|
||||
progress: asString(json['progress']),
|
||||
projectedDate: asDate(json['projected_date']),
|
||||
basis: asString(json['basis']) ?? 'none',
|
||||
assumedRate: asString(json['assumed_rate']),
|
||||
monthlyNeededRub: asString(json['monthly_needed_rub']),
|
||||
onTrack: asBool(json['on_track']),
|
||||
);
|
||||
goalId: asInt(json['goal_id']) ?? 0,
|
||||
asOf: asDate(json['as_of']),
|
||||
currentValueRub: asString(json['current_value_rub']),
|
||||
targetAmountRub: asString(json['target_amount_rub']),
|
||||
progress: asString(json['progress']),
|
||||
projectedDate: asDate(json['projected_date']),
|
||||
basis: asString(json['basis']) ?? 'none',
|
||||
assumedRate: asString(json['assumed_rate']),
|
||||
monthlyNeededRub: asString(json['monthly_needed_rub']),
|
||||
onTrack: asBool(json['on_track']),
|
||||
);
|
||||
}
|
||||
|
||||
class GoalsApi {
|
||||
@@ -142,7 +142,10 @@ class GoalsApi {
|
||||
}
|
||||
|
||||
Future<Goal> patch(int id, Map<String, dynamic> changes) async {
|
||||
final r = await _dio.patch<Map<String, dynamic>>('$_base/$id', data: changes);
|
||||
final r = await _dio.patch<Map<String, dynamic>>(
|
||||
'$_base/$id',
|
||||
data: changes,
|
||||
);
|
||||
return Goal.fromJson(r.data ?? const {});
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,8 @@ const goalBasisLabels = {
|
||||
|
||||
const goalBasisDescriptions = {
|
||||
'xirr': 'Прогноз построен на фактической доходности портфеля (XIRR).',
|
||||
'contribution': 'Прогноз построен на регулярных взносах, без учёта доходности.',
|
||||
'contribution':
|
||||
'Прогноз построен на регулярных взносах, без учёта доходности.',
|
||||
'none': 'Данных для прогноза нет: ни доходности, ни истории взносов.',
|
||||
};
|
||||
|
||||
@@ -58,12 +59,15 @@ class GoalCard extends ConsumerWidget {
|
||||
Text(
|
||||
[
|
||||
'цель ${MoneyText.format(goal.targetAmount, goal.currency)}',
|
||||
if (goal.targetDate != null) 'к ${ruDate(goal.targetDate!)}',
|
||||
if (goal.targetDate != null)
|
||||
'к ${ruDate(goal.targetDate!)}',
|
||||
if (goal.monthlyContribution != null)
|
||||
'взнос ${MoneyText.format(goal.monthlyContribution!, goal.currency)}/мес',
|
||||
if (goal.archived) 'в архиве',
|
||||
].join(' · '),
|
||||
style: theme.textTheme.bodySmall?.copyWith(color: theme.hintColor),
|
||||
style: theme.textTheme.bodySmall?.copyWith(
|
||||
color: theme.hintColor,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -86,7 +90,8 @@ class GoalCard extends ConsumerWidget {
|
||||
AsyncValueView(
|
||||
value: progress,
|
||||
onRetry: () => ref.invalidate(goalProgressProvider(goal.id)),
|
||||
data: (cached) => GoalProgressView(goal: goal, progress: cached.data),
|
||||
data: (cached) =>
|
||||
GoalProgressView(goal: goal, progress: cached.data),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -98,7 +103,11 @@ class GoalCard extends ConsumerWidget {
|
||||
/// The progress body, split out of [GoalCard] so it can be rendered (and tested) without a
|
||||
/// provider container.
|
||||
class GoalProgressView extends StatelessWidget {
|
||||
const GoalProgressView({required this.goal, required this.progress, super.key});
|
||||
const GoalProgressView({
|
||||
required this.goal,
|
||||
required this.progress,
|
||||
super.key,
|
||||
});
|
||||
|
||||
final Goal goal;
|
||||
final GoalProgress progress;
|
||||
@@ -150,15 +159,17 @@ class GoalProgressView extends StatelessWidget {
|
||||
Icon(
|
||||
unreachable ? Icons.trending_flat : Icons.flag_outlined,
|
||||
size: 18,
|
||||
color: unreachable ? theme.colorScheme.error : theme.colorScheme.primary,
|
||||
color: unreachable
|
||||
? theme.colorScheme.error
|
||||
: theme.colorScheme.primary,
|
||||
),
|
||||
const SizedBox(width: 8),
|
||||
Expanded(
|
||||
child: Text(
|
||||
unreachable
|
||||
? (progress.basis == 'none'
|
||||
? 'Прогноз недоступен: данных для оценки тренда пока нет'
|
||||
: 'При текущем тренде цель не достигается')
|
||||
? 'Прогноз недоступен: данных для оценки тренда пока нет'
|
||||
: 'При текущем тренде цель не достигается')
|
||||
: 'Прогнозная дата достижения: ${ruDate(progress.projectedDate!)}',
|
||||
style: theme.textTheme.bodyMedium?.copyWith(
|
||||
color: unreachable ? theme.colorScheme.error : null,
|
||||
@@ -177,7 +188,7 @@ class GoalProgressView extends StatelessWidget {
|
||||
progress.monthlyNeededRub == null
|
||||
? 'Нужный ежемесячный взнос: — (нет целевой даты)'
|
||||
: 'Нужно докладывать: '
|
||||
'${MoneyText.format(progress.monthlyNeededRub!, 'RUB')}/мес',
|
||||
'${MoneyText.format(progress.monthlyNeededRub!, 'RUB')}/мес',
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
if (progress.assumedRate != null)
|
||||
@@ -192,7 +203,10 @@ class GoalProgressView extends StatelessWidget {
|
||||
),
|
||||
),
|
||||
if (progress.asOf != null)
|
||||
Text('на ${ruDate(progress.asOf!)}', style: theme.textTheme.bodySmall),
|
||||
Text(
|
||||
'на ${ruDate(progress.asOf!)}',
|
||||
style: theme.textTheme.bodySmall,
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
|
||||
@@ -20,9 +20,12 @@ class GoalEditDialog extends ConsumerStatefulWidget {
|
||||
class _GoalEditDialogState extends ConsumerState<GoalEditDialog> {
|
||||
final _formKey = GlobalKey<FormState>();
|
||||
late final _name = TextEditingController(text: widget.initial?.name ?? '');
|
||||
late final _amount = TextEditingController(text: widget.initial?.targetAmount ?? '');
|
||||
late final _contribution =
|
||||
TextEditingController(text: widget.initial?.monthlyContribution ?? '');
|
||||
late final _amount = TextEditingController(
|
||||
text: widget.initial?.targetAmount ?? '',
|
||||
);
|
||||
late final _contribution = TextEditingController(
|
||||
text: widget.initial?.monthlyContribution ?? '',
|
||||
);
|
||||
late final _note = TextEditingController(text: widget.initial?.note ?? '');
|
||||
late String _scope = widget.initial?.scope ?? 'all';
|
||||
late DateTime? _targetDate = widget.initial?.targetDate;
|
||||
@@ -71,7 +74,8 @@ class _GoalEditDialogState extends ConsumerState<GoalEditDialog> {
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
DropdownButtonFormField<String>(
|
||||
initialValue: scopes.any((s) => s.scope == _scope) || _scope == 'all'
|
||||
initialValue:
|
||||
scopes.any((s) => s.scope == _scope) || _scope == 'all'
|
||||
? _scope
|
||||
: 'all',
|
||||
decoration: const InputDecoration(labelText: 'Что считаем'),
|
||||
@@ -86,14 +90,20 @@ class _GoalEditDialogState extends ConsumerState<GoalEditDialog> {
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _amount,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
decoration: const InputDecoration(labelText: 'Целевая сумма, ₽'),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Целевая сумма, ₽',
|
||||
),
|
||||
validator: _decimalValidator,
|
||||
),
|
||||
const SizedBox(height: 12),
|
||||
TextFormField(
|
||||
controller: _contribution,
|
||||
keyboardType: const TextInputType.numberWithOptions(decimal: true),
|
||||
keyboardType: const TextInputType.numberWithOptions(
|
||||
decimal: true,
|
||||
),
|
||||
decoration: const InputDecoration(
|
||||
labelText: 'Ежемесячный взнос, ₽',
|
||||
helperText: 'необязательно',
|
||||
@@ -104,20 +114,25 @@ class _GoalEditDialogState extends ConsumerState<GoalEditDialog> {
|
||||
Row(
|
||||
children: [
|
||||
Expanded(
|
||||
child: Text(_targetDate == null
|
||||
? 'Целевая дата не задана'
|
||||
: 'Целевая дата: ${ruDate(_targetDate!)}'),
|
||||
child: Text(
|
||||
_targetDate == null
|
||||
? 'Целевая дата не задана'
|
||||
: 'Целевая дата: ${ruDate(_targetDate!)}',
|
||||
),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () async {
|
||||
final now = DateTime.now();
|
||||
final picked = await showDatePicker(
|
||||
context: context,
|
||||
initialDate: _targetDate ?? DateTime(now.year + 3, now.month, now.day),
|
||||
initialDate:
|
||||
_targetDate ??
|
||||
DateTime(now.year + 3, now.month, now.day),
|
||||
firstDate: DateTime(now.year - 1),
|
||||
lastDate: DateTime(now.year + 50),
|
||||
);
|
||||
if (picked != null) setState(() => _targetDate = picked);
|
||||
if (picked != null)
|
||||
setState(() => _targetDate = picked);
|
||||
},
|
||||
child: const Text('Выбрать'),
|
||||
),
|
||||
@@ -147,21 +162,26 @@ class _GoalEditDialogState extends ConsumerState<GoalEditDialog> {
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Отмена')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(),
|
||||
child: const Text('Отмена'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () {
|
||||
if (!(_formKey.currentState?.validate() ?? false)) return;
|
||||
Navigator.of(context).pop(Goal(
|
||||
id: widget.initial?.id ?? 0,
|
||||
name: _name.text.trim(),
|
||||
scope: _scope,
|
||||
targetAmount: _decimal(_amount.text) ?? '0',
|
||||
currency: widget.initial?.currency ?? 'RUB',
|
||||
targetDate: _targetDate,
|
||||
monthlyContribution: _decimal(_contribution.text),
|
||||
note: _note.text.trim().isEmpty ? null : _note.text.trim(),
|
||||
archived: _archived,
|
||||
));
|
||||
Navigator.of(context).pop(
|
||||
Goal(
|
||||
id: widget.initial?.id ?? 0,
|
||||
name: _name.text.trim(),
|
||||
scope: _scope,
|
||||
targetAmount: _decimal(_amount.text) ?? '0',
|
||||
currency: widget.initial?.currency ?? 'RUB',
|
||||
targetDate: _targetDate,
|
||||
monthlyContribution: _decimal(_contribution.text),
|
||||
note: _note.text.trim().isEmpty ? null : _note.text.trim(),
|
||||
archived: _archived,
|
||||
),
|
||||
);
|
||||
},
|
||||
child: const Text('Сохранить'),
|
||||
),
|
||||
|
||||
@@ -23,7 +23,8 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
bool _showArchived = false;
|
||||
|
||||
void _snack(String message) =>
|
||||
ScaffoldMessenger.of(context).showSnackBar(SnackBar(content: Text(message)));
|
||||
ScaffoldMessenger.of(context)
|
||||
.showSnackBar(SnackBar(content: Text(message)));
|
||||
|
||||
Future<void> _create() async {
|
||||
final goal = await showDialog<Goal>(
|
||||
@@ -62,8 +63,14 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
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('Удалить')),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(false),
|
||||
child: const Text('Отмена'),
|
||||
),
|
||||
FilledButton(
|
||||
onPressed: () => Navigator.of(ctx).pop(true),
|
||||
child: const Text('Удалить'),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
@@ -82,10 +89,13 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
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 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,
|
||||
for (final id in goalIds)
|
||||
ref.watch(goalProgressProvider(id)).valueOrNull?.fetchedAt,
|
||||
]);
|
||||
|
||||
return Scaffold(
|
||||
@@ -94,7 +104,9 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
actions: [
|
||||
IconButton(
|
||||
tooltip: _showArchived ? 'Скрыть архив' : 'Показать архив',
|
||||
icon: Icon(_showArchived ? Icons.inventory_2 : Icons.inventory_2_outlined),
|
||||
icon: Icon(
|
||||
_showArchived ? Icons.inventory_2 : Icons.inventory_2_outlined,
|
||||
),
|
||||
onPressed: () => setState(() => _showArchived = !_showArchived),
|
||||
),
|
||||
IconButton(
|
||||
@@ -116,7 +128,9 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
onRetry: () => ref.invalidate(goalsProvider),
|
||||
data: (cached) {
|
||||
final all = cached.data;
|
||||
final rows = _showArchived ? all : all.where((g) => !g.archived).toList();
|
||||
final rows = _showArchived
|
||||
? all
|
||||
: all.where((g) => !g.archived).toList();
|
||||
if (rows.isEmpty) {
|
||||
return ListView(
|
||||
padding: const EdgeInsets.all(16),
|
||||
@@ -127,7 +141,7 @@ class _GoalsPageState extends ConsumerState<GoalsPage> {
|
||||
icon: Icons.flag_outlined,
|
||||
message: all.isEmpty
|
||||
? 'Целей пока нет.\nЦель — это сумма и (необязательно) дата; '
|
||||
'прогноз считает сервер по доходности или по взносам.'
|
||||
'прогноз считает сервер по доходности или по взносам.'
|
||||
: 'Все цели в архиве — включите показ архива.',
|
||||
),
|
||||
],
|
||||
|
||||
@@ -4,18 +4,21 @@ import '../../core/api/api_client.dart';
|
||||
import '../../core/cache/cached.dart';
|
||||
import 'data/goals_api.dart';
|
||||
|
||||
final goalsApiProvider = Provider<GoalsApi>((ref) => GoalsApi(ref.watch(apiProvider).dio));
|
||||
final goalsApiProvider = Provider<GoalsApi>(
|
||||
(ref) => GoalsApi(ref.watch(apiProvider).dio),
|
||||
);
|
||||
|
||||
/// See `docs/ai/offline-cache.md`.
|
||||
final goalsProvider =
|
||||
FutureProvider.autoDispose<Cached<List<Goal>>>((ref) => ref.watch(goalsApiProvider).list());
|
||||
final goalsProvider = FutureProvider.autoDispose<Cached<List<Goal>>>(
|
||||
(ref) => ref.watch(goalsApiProvider).list(),
|
||||
);
|
||||
|
||||
/// Progress is computed server-side and refetched per goal — the client never projects
|
||||
/// anything itself.
|
||||
final goalProgressProvider =
|
||||
FutureProvider.autoDispose.family<Cached<GoalProgress>, int>((ref, id) async {
|
||||
return ref.watch(goalsApiProvider).progress(id);
|
||||
});
|
||||
final goalProgressProvider = FutureProvider.autoDispose
|
||||
.family<Cached<GoalProgress>, int>((ref, id) async {
|
||||
return ref.watch(goalsApiProvider).progress(id);
|
||||
});
|
||||
|
||||
/// After any create/patch/delete the list and every progress card are refetched: the
|
||||
/// numbers are recomputed on the server, not patched in the app.
|
||||
|
||||
Reference in New Issue
Block a user