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
@@ -0,0 +1,120 @@
import 'package:flutter/material.dart';
import '../../portfolio/labels.dart' show assetClassLabel;
import '../data/pending_api.dart';
/// The form behind `action: "create"`. Fields are prefilled from what the report literally
/// said about this line (ISIN, ticker, name, currency) — that is transcription, not a guess
/// about which instrument it is; the user still confirms every field before submitting.
class CreateInstrumentDialog extends StatefulWidget {
const CreateInstrumentDialog({required this.pending, super.key});
final PendingInstrument pending;
@override
State<CreateInstrumentDialog> createState() => _CreateInstrumentDialogState();
}
class _CreateInstrumentDialogState extends State<CreateInstrumentDialog> {
final _formKey = GlobalKey<FormState>();
late final _isin = TextEditingController(text: widget.pending.isin ?? '');
late final _ticker = TextEditingController(text: widget.pending.ticker ?? '');
late final _board = TextEditingController(text: widget.pending.board ?? '');
late final _name = TextEditingController(text: widget.pending.name ?? '');
late final _currency = TextEditingController(text: widget.pending.currency ?? 'RUB');
late final _lot = TextEditingController(text: '1');
/// `asset_class_hint` is what the report's own section said (e.g. the «Фонды» table), so
/// it is offered as the initial value of a control the user must still look at.
late String _assetClass = assetClassKeys.contains(widget.pending.assetClassHint)
? widget.pending.assetClassHint!
: 'share';
@override
void dispose() {
_isin.dispose();
_ticker.dispose();
_board.dispose();
_name.dispose();
_currency.dispose();
_lot.dispose();
super.dispose();
}
void _submit() {
if (!_formKey.currentState!.validate()) return;
Navigator.of(context).pop(NewInstrument(
assetClass: _assetClass,
name: _name.text.trim(),
currency: _currency.text.trim().toUpperCase(),
isin: _isin.text.trim(),
ticker: _ticker.text.trim(),
board: _board.text.trim(),
lot: int.tryParse(_lot.text.trim()),
));
}
@override
Widget build(BuildContext context) {
return AlertDialog(
title: const Text('Создать инструмент'),
content: SizedBox(
width: 480,
child: Form(
key: _formKey,
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
DropdownButtonFormField<String>(
initialValue: _assetClass,
isExpanded: true,
decoration: const InputDecoration(labelText: 'Класс актива'),
items: [
for (final key in assetClassKeys)
DropdownMenuItem(value: key, child: Text('${assetClassLabel(key)} ($key)')),
],
onChanged: (v) => setState(() => _assetClass = v ?? _assetClass),
),
_field(_name, 'Название', required: true),
_field(_isin, 'ISIN'),
_field(_ticker, 'Тикер'),
_field(_board, 'Доска (TQBR, TQTF…)'),
_field(_currency, 'Валюта', required: true),
_field(_lot, 'Лот', keyboard: TextInputType.number, validator: (v) {
if (v == null || v.trim().isEmpty) return null;
return int.tryParse(v.trim()) == null ? 'Целое число' : null;
}),
],
),
),
),
),
actions: [
TextButton(onPressed: () => Navigator.of(context).pop(), child: const Text('Отмена')),
FilledButton(onPressed: _submit, child: const Text('Создать и привязать')),
],
);
}
Widget _field(
TextEditingController controller,
String label, {
bool required = false,
TextInputType? keyboard,
String? Function(String?)? validator,
}) {
return Padding(
padding: const EdgeInsets.only(top: 12),
child: TextFormField(
controller: controller,
keyboardType: keyboard,
decoration: InputDecoration(labelText: label, isDense: true),
validator: validator ??
(required
? (v) => (v == null || v.trim().isEmpty) ? 'Обязательное поле' : null
: null),
),
);
}
}
@@ -0,0 +1,119 @@
import 'dart:async';
import 'package:fintracker_api/fintracker_api.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../portfolio/labels.dart' show assetClassLabel;
import '../providers.dart';
/// Search-and-pick over `GET /instruments?q=`. Deliberately dumb: it shows what the search
/// returned and nothing else — no "probably this one" pre-selection, no highlighted best
/// guess. The binding is the user's statement, not the app's inference.
class LinkInstrumentDialog extends ConsumerStatefulWidget {
const LinkInstrumentDialog({required this.initialQuery, super.key});
/// Prefilled search text (the ISIN or ticker from the report). It only fills the search
/// box — nothing is selected until the user taps a row.
final String initialQuery;
@override
ConsumerState<LinkInstrumentDialog> createState() => _LinkInstrumentDialogState();
}
class _LinkInstrumentDialogState extends ConsumerState<LinkInstrumentDialog> {
late final TextEditingController _controller =
TextEditingController(text: widget.initialQuery);
String _query = '';
Timer? _debounce;
@override
void initState() {
super.initState();
_query = widget.initialQuery;
}
@override
void dispose() {
_debounce?.cancel();
_controller.dispose();
super.dispose();
}
void _onChanged(String value) {
_debounce?.cancel();
_debounce = Timer(const Duration(milliseconds: 350), () {
if (mounted) setState(() => _query = value);
});
}
@override
Widget build(BuildContext context) {
final results = ref.watch(instrumentSearchProvider(_query));
return AlertDialog(
title: const Text('Привязать к инструменту'),
content: SizedBox(
width: 520,
height: 420,
child: Column(
children: [
TextField(
controller: _controller,
autofocus: true,
decoration: const InputDecoration(
prefixIcon: Icon(Icons.search),
hintText: 'Тикер, ISIN или название',
border: OutlineInputBorder(),
isDense: true,
),
onChanged: _onChanged,
),
const SizedBox(height: 12),
Expanded(
child: results.when(
loading: () => const Center(child: CircularProgressIndicator()),
error: (e, _) => Center(child: Text('$e')),
data: (rows) {
if (_query.trim().length < 2) {
return const Center(child: Text('Введите минимум 2 символа'));
}
if (rows.isEmpty) {
return const Center(child: Text('Ничего не найдено'));
}
return ListView.builder(
itemCount: rows.length,
itemBuilder: (context, i) => _row(rows[i]),
);
},
),
),
],
),
),
actions: [
TextButton(
onPressed: () => Navigator.of(context).pop(),
child: const Text('Отмена'),
),
],
);
}
Widget _row(InstrumentOut instrument) {
final subtitle = [
assetClassLabel(instrument.assetClass),
if (instrument.isin != null) instrument.isin!,
if (instrument.board != null) instrument.board!,
instrument.currency,
].join(' · ');
return ListTile(
dense: true,
title: Text([
if (instrument.ticker != null) instrument.ticker!,
instrument.name,
].join(' · ')),
subtitle: Text(subtitle),
onTap: () => Navigator.of(context).pop(instrument.id),
);
}
}